Home > Software engineering >  Use msbuild or dotnet to render csproj without building
Use msbuild or dotnet to render csproj without building

Time:07-28

My Foo.csproj uses variables. For example:

<SolutionName>MyCompany</SolutionName>
<Authors>$(SolutionName)</Authors>

In my build scripts I need to know the value of various properties. I thought that would be possible using the dotnet or msbuild CLIs, so I tried:

msbuild -pp Foo.csproj

...but although that merges config, it doesn't render variables.

Is there some way I can get the rendered xml?

dotnet 6.0.302
msbuild 16.5.0.26101

(Maybe there's a dotnet tool for this sort of thing - but I prefer a built-in solution.)

CodePudding user response:

The -pp switch outputs the result of performing all imports. Properties are not evaluated by -pp.

Properties are not static and their values changes over the run of a MSBuild script. If you are troubleshooting and you need to know the value of a variable at a specific point in your MSBuild script, use the Message task to display the value.

The -v:d and -d:diag switches can be used to get more detail in logs including the starting values of certain properties.

CodePudding user response:

Currently this isn't possible, but there is a feature request on the repo for this. They seem to be open to adding this functionality, in some form (possibly rendering a specific property, rather than the entire csproj, but even that would be useful).

Upvote that issue if you need this functionality.

  • Related