Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can .csproj know about its solution?

In .csproj files you can use variables like $(SolutionDir). It's possible to find libraries that way.

How it's possible you can build .csproj by msbuild (not giving it solution path)? I can't see any sense in such behaviour, but it's working anyway.

like image 540
Maciej Oziębły Avatar asked Jan 28 '15 15:01

Maciej Oziębły


1 Answers

Individual project files do not have awareness of what solution they are part of. Variables $(SolutionDir), $(SolutionPath), $(SolutionExt), etc, only defined when you build your .sln file, they are not defined when you build project directly.

To illustrate this, place this in your project file:

<Target Name="BeforeBuild">
  <Message Text="SolutionDir=$(SolutionDir)" />
</Target>

When you build the solution you get this:

>msbuild sln.sln
Microsoft (R) Build Engine version 12.0.31101.0
...
BeforeBuild:
  SolutionDir=e:\temp\sln\
...

When you build your project directly you get this:

>msbuild fs\fs.fsproj
Microsoft (R) Build Engine version 12.0.31101.0 
...
BeforeBuild:
  SolutionDir=*Undefined*
...

As you can see, $(SolutionDir) is badly broken. I don't recommend using it, along with other $(Solution***) variables, because you will want at some point to build project directly, or create new .sln file with different subset of your projects in other directory, and then you will run into build breaks.

like image 79
seva titov Avatar answered Oct 20 '22 17:10

seva titov