How can .csproj know about its solution?

微笑、不失礼 提交于 2019-12-05 09:56:31

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!