c# - 在项目扩展中使用 Msbuild 变量

标签 c# asp.net visual-studio asp.net-web-api msbuild

我目前有一个 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/

相关文章:

asp.net - 将规则重写为 WWW,除非在本地主机上

asp.net - 我怎样才能在asp.net的立即窗口中做空Arraylist

关于我的文件声明的 C2015 错误

c# - 如何将自定义窗口窗体置于安装项目窗口顶部?

c# - Xamarin.iOS MKLaunchOptionsDirectionsModeKey

c# - 如何在 EF Core 中使用 LINQ 将原始数据类型列表与实体连接起来?

c# - 组合框不在 C# 的 DataGridView 中显示默认值

asp.net - 移植到 ASP.NET MVC 的推荐方法

visual-studio - 在 Visual Studio 2013 中全局使用 UNIX 行结尾

c# - Web应用中, "ressource cannot be found"异常时当前session为null