.net - 从 Visual Studio 2015 构建时自动发布 Web 应用程序

标签 .net visual-studio-2015 publish

有没有办法在成功构建时使用预先创建的发布配置文件自动发布 Web 应用程序?
我不想单击发布图标,需要在 Visual Studio 2015 上成功构建 Web 项目时发生这种情况 - 不使用宏。

任何 sample 将不胜感激!

最佳答案

Rami 的解决方案有效,但它需要另一个“构建” channel 。虽然这实际上不会重新编译,但如果您的解决方案很大,它仍然会导致不必要的延迟。

您无法通过 DeployOnBuild 触发网络发布因为从 Visual Studio 构建时会自动禁用。

但是,您可以通过一些 MSBuild 技巧,在同一 MSBuild 调用中触发该过程:

<!-- In Directory.Build.props or the csproj (before the web targets import) -->
<PropertyGroup>
  <PublishProfile>Local</PublishProfile>
</PropertyGroup>

并且:
<!-- After the above, or in ProjectName.wpp.targets -->
<PropertyGroup>
  <AutoPublish Condition="'$(AutoPublish)' == '' and '$(Configuration)' == 'Debug' and '$(BuildingInsideVisualStudio)' == 'true' and '$(PublishProfile)' != ''">true</AutoPublish>

  <AutoPublishDependsOn Condition="'$(AutoPublish)' == 'true'">
    $(AutoPublishDependsOn);
    WebPublish
  </AutoPublishDependsOn>
</PropertyGroup>

<Target Name="AutoPublish" AfterTargets="Build" DependsOnTargets="$(AutoPublishDependsOn)">
</Target>

如果您发现在进行内容更改时未构建发布项目,请添加以下内容:
<!-- csproj ONLY, won't work elsewhere -->
<PropertyGroup>
  <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>

关于.net - 从 Visual Studio 2015 构建时自动发布 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42761282/

相关文章:

c# - 未能发布 : could not find required file 'setup.bin'

mysql - 发布应用后找不到数据库

android - 不同证书的apk

.net - Linq to Xml:异常-名称中不能包含''字符,十六进制值0x20

c# - 在 propertygrid 中将属性更改为组合框

c++ - TRK0005错误定位rc.exe构建VC++ 2015项目

C struct object Stack - 常量表达式中不允许函数调用(错误)

c# - 企业库日志记录应用程序 block - System.InvalidOperationException : The LogWriter is already set

.net - Roslyn C# 编译器如何知道在哪里可以找到 .NET 程序集文件?

c# - 以编程方式停止 DTS 包(使用 C#)