我目前有一个 web.api 项目的解决方案,我想将其部署到本地 IIS 中的不同虚拟目录。目前我正在 api 的 .csproj 中执行以下操作:
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)' == 'CustomerOne.Debug'">
<CustomerName>CustomerOne</CustomerName>
....
</PropertyGroup>
...
这些变量进一步广泛用于 web.config 转换、复制到不同位置等,通过像 $(CustomerName)
一样引用它们.
它唯一不起作用的地方是在虚拟目录的定义中,即我想将构建配置连接到 IISUrl
下面,您可以对其进行硬编码:
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
...
<IISUrl>http://localhost/api/something</IISUrl>
...
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
将其替换为 <IISUrl>http://localhost/api/$(CustomerName)</IISUrl>
不起作用。想法?
最佳答案
Replacing this by http://localhost/api/$(CustomerName) does not work. Ideas?
那是因为 ProjectExtensions 元素内的任何内容都将被 MSBuild 忽略。
您可以从本文档中获取详细信息ProjectExtensions Element (MSBuild) :
Allows MSBuild project files to contain non-MSBuild information. Anything inside of a ProjectExtensions element will be ignored by MSBuild.
这就是 Msbuild 变量在项目扩展中不起作用的原因。
希望这对您有所帮助。
关于c# - 在项目扩展中使用 Msbuild 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54112404/