【发布时间】:2019-06-04 08:41:08
【问题描述】:
我目前有一个 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> 替换它不起作用。想法?
【问题讨论】:
-
澄清一下:Leo Lui-MSFT 的回答已经回答了为什么它不起作用。我对如何让它工作很感兴趣,即如何根据构建配置配置 IISUrl。
-
声音类似于我过去遇到的问题。看看this answer提供的解决方案。这个想法是使用
DefineConstants。
标签: c# asp.net visual-studio asp.net-web-api msbuild