AnswerBun.com

$(ProjectName) and $(TargetName) MSBuild macros not working

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?

Stack Overflow Asked by Ivan Caravanio on February 22, 2021

2 Answers

2 Answers

Do not try to import Microsoft.CSharp.targets - like suggested in another answer. First of all - it will lead to additional warning like

Warning MSB4011: "Microsoft.CSharp.targets" cannot be imported again. ...

But additionally to that if you try to edit pre-/post- build Visual studio will crash. (Observed in Visual studio 2019, 16.7.7 version)

Better to use $(MSBuildProjectName) macro instead of $(ProjectName) - works identically.

Answered by TarmoPikaro on February 22, 2021

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.

Answered by Steven Spyrka on February 22, 2021

Add your own answers!

Related Questions

Removing duplicates while sorting numbers inside a String in java

5  Asked on November 30, 2020 by swetha-haridoss

       

pointers cant read the correct elements in array

2  Asked on November 29, 2020 by jabou

   

pandas does not load the sub packages properly

0  Asked on November 29, 2020 by realbro

   

Webpack: how to copy html files into build folder?

2  Asked on November 29, 2020 by wai-yan-hein

   

Save string to file without converting newlines using Python

1  Asked on November 29, 2020 by kleiton-kurti

       

ngx-mask Do not allow negative value for the currency input

2  Asked on November 28, 2020 by ashot-aleqsanyan

   

Unity: Add extra time to slider

1  Asked on November 28, 2020 by christopher-madsen

     

Python cannot access list

3  Asked on November 28, 2020 by forge-mods

   

Get property name and value only if there is a value

1  Asked on November 28, 2020 by jimenemex

   

Count percentage of upper case words

1  Asked on November 28, 2020 by user13623188

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.