Visual Studio 发布 MSdeploy $(SolutionDir)

Visual Studio Publish MSdeploy $(SolutionDir)

我在使用 MSDeploy 和 Visual Studio 的发布配置文件时遇到了一个烦人的问题。在我的项目中,我有一个 属性 组,我设置了一个项目供以后参考。

<LocalBuildLocation>$(SolutionDir)WebSites\MyWebSite\</LocalBuildLocation>

不幸的是,Visual Studio 将从这个 属性 中随机删除 $(SolutionDir) 字符串,我的构建将失败。我手动将其复制回去,一切正常。

谁能想到为什么这个项目不断地删除自己?

来自 MSDN:在程序集和包含指令中使用项目属性

Visual Studio macros like $(SolutionDir) don’t work in MSBuild. You can use project properties instead.

使用$(ProjectDir)(更安全,项目级别属性)或$(MSBuildProjectDirectory)(最安全,始终存在)

参见: and getting the value of $(ProjectDir), $(SolutionDir) in a vcproj file

看起来 $SolutionDir 确实(有时)使用 MSBuild,但前提是您是从解决方案文件构建的。在大多数情况下,它与 $ProjectDir 相同。

但是您不能在 MSBuild 中使用它们。尽管它们有时会起作用——但它并不可靠。正如另一个答案所指出的那样:

Visual Studio macros like $(SolutionDir) don’t work in MSBuild. You can use project properties instead.

来源:Code Generation in a Build Process

$(ProjectDir) The directory of the project (defined as drive + path); includes the trailing backslash '\'.

$(SolutionDir) The directory of the solution (defined as drive + path); includes the trailing backslash '\'.

注意:

You can use these macros anywhere in a project's Property Pages dialog box where strings are accepted.

来源:Macros for Build Commands and Properties