.csproj如何知道其解决方案? [英] How can .csproj know about its solution?

查看:46
本文介绍了.csproj如何知道其解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.csproj文件中,您可以使用$(SolutionDir)之类的变量.可以通过这种方式找到库.

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

您怎么可能通过msbuild构建.csproj(不提供解决方案路径)?我看不到这种行为有任何意义,但是无论如何它都在起作用.

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.

推荐答案

单个项目文件没有知道它们属于什么解决方案.变量$(SolutionDir),$(SolutionPath),$(SolutionExt)等仅在构建.sln文件时定义,而在直接构建项目时则未定义.

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*
...

如您所见,$(SolutionDir)严重损坏.我不建议将其与其他$(Solution ***)变量一起使用,因为您有时会希望直接构建项目,或者在其他目录中使用项目的不同子集创建新的.sln文件,然后您将遇到构建中断.

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.

这篇关于.csproj如何知道其解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆