How to print the value of an MSBuild <Property> inside the environment?

StackOverflow https://stackoverflow.com/questions/22157897

  •  19-10-2022
  •  | 
  •  

質問

I'm using Visual Studio 2013. I am writing some MSBuild by hand. Inside I have something like this:

<PropertyGroup>
  <MyProperty>(complicated function)</MyProperty>
<PropertyGroup>

I load my project. I'd like some command, perhaps that I can execute in the immediate window, to print the value of "MyProperty".

What is the normal way of achieving this?

Edit: I discovered that I can make a <Target> that prints the value of all my properties with the <Message> task, but I can't find an easy way to execute this target from within the environment. I can set it as the DefaultTarget on the <Project>, but then I have to unload the project and edit the file again to get back to a state where I can actually compile.

Supposedly I could do this using msbuild.exe /t from the command line, but it doesn't seem to work because the properties, and also the <Target> itself, are defined in a file which is included via an <Import> statement, and for some reason msbuild.exe /t doesn't seem to like that.

役に立ちましたか?

解決

MSBuild allows you to debug the script in Visual Studio,

http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx

You can also force verbose logging, by adding /v:diag to your MSBuild command line, where in the log all such variables can be easily analyzed.

There is really no need to do what you plan to do.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top