我试图让我的 Web 应用程序在执行发布构建时自动发布。我正在使用 _CopyWebApplication 目标执行此操作。我将以下内容添加到我的 .csproj 文件中:
<!-- Automatically Publish in Release build. -->
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="AfterBuild">
<RemoveDir Directories="$(ProjectDir)..\Output\MyWeb" ContinueOnError="true" />
<MSBuild Projects="MyWeb.csproj" Properties="Configuration=Release;WebProjectOutputDir=$(ProjectDir)..\Output\MyWeb;OutDir=$(ProjectDir)bin\" Targets="ResolveReferences;_CopyWebApplication" />
</Target>
这有效,但有一个问题。此输出与在 Visual Studio 中使用“发布”菜单项时生成的输出之间的区别在于,使用 MSBuild 方法时,Web.Release.config 转换未应用于 Web.config 文件。相反,Web.config、Web.Release.config 和 Web.Debug.config 都被复制。
任何想法表示赞赏。