Msbuild script using solution information

I have a csproj file that is part of two different Visual Studio solutions. The project file should behave a little differently, depending on the solution from which it will be used. What I need is what can be used as a β€œCondition” - a property named, for example, $ (SolutionName) - is automatically filled. At least that's my idea. I did not find anything like it.

I also thought that two small project files import common parts. This would probably prevent all of these properties from being edited inside Visual Studio. It will only record changes in the active "main file", right?

So, is there any other way of recognizing at the project level using solution information?

+4
source share
1 answer

It turns out there is a property named exactly $ (SolutionName). Try it; first set the environment variable as:

> set MSBuildEmitSolution=1 

Then create a solution file using MSBuild from the same command line

 > MSBuild My.sln 

You will find the conversion of the MSBuild project to a solution file, it will be called My.sln.metaproj .

Just open it in a text editor and you will see other properties. Examine the Create target in this projectd file, you will see that all these properties are passed to the MSBuild task when it is created, so you should be able to distinguish between conditions based on any of them.

+7
source

Source: https://habr.com/ru/post/1346780/


All Articles