$(ProjectName) and $(TargetName) MSBuild macros no

2019-08-05 18:21发布

问题:

I am using Visual Stduio 2015 Community Edition. I have loaded a C# project and want to configure it to use shadow building, so that source files are not messed up with any binaries or intermediate build files. Tried to set the [output]/[intermediate output] directory paths of the C# project using the VS UI - the only UI-editable output path is the "bin" one and it doesn't accept MSBuild macros. Then I've unloaded the project and manually edited it. Also set the IntermediateOutputPath which is not available in the VS UI when using C# project, but when using C++ one all such kind of directories are editable. Currently, the OutputPath is set to: <OutputPath>$(SolutionDir)..\build_$(SolutionName)_$(Configuration)_$(Platform)\$(ProjectName)</OutputPath>

$(ProjectName) is empty for some reason. Tried $(TargetName) (it is not correct to use it but just for the test) but it is empty, too. Any suggestions?

回答1:

The problem is that some of the MSBuild properties like ProjectName are set after the following line in your .csproj file.

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

After this line you can access all variables.