Visual studio 在web部署输出中包括web.release.config
默认情况下,使用MSBuild/Visual Studio发布Web项目时,将应用配置转换 我希望在输出中包含配置转换 输入 默认输出 期望输出 使用Visual Studio将文件生成操作更新为内容,例如右键单击、属性 发布任务仍将转换文件,因此我们需要告诉MSBuild,我们不希望在发布时转换这些文件 这可以通过将以下参数传递到MSBuild中来实现: /p:ProfileTransformWebConfigEnabled=false/p:MarkWebConfigGassistFilesASExclude=false 如果您在Visual Studio中工作,可以通过将这些属性添加到PublishProfile.xml来测试此行为 在web部署输出中包括web.release.config 默认情况下,发布网站时,VS不打包web.debug.config和web.release.config,而只打包web.config 要实现所需的功能,可以将自定义目标添加到publishprofile.pubxml中,以包含这些额外的文件 请试试这个:Visual studio 在web部署输出中包括web.release.config,visual-studio,msbuild,webdeploy,octopus,Visual Studio,Msbuild,Webdeploy,Octopus,默认情况下,使用MSBuild/Visual Studio发布Web项目时,将应用配置转换 我希望在输出中包含配置转换 输入 默认输出 期望输出 使用Visual Studio将文件生成操作更新为内容,例如右键单击、属性 发布任务仍将转换文件,因此我们需要告诉MSBuild,我们不希望在发布时转换这些文件 这可以通过将以下参数传递到MSBuild中来实现: /p:ProfileTransformWebConfigEnabled=false/p:MarkWebConfigGassistFilesA
<Target Name="CustomCollectFiles">
<ItemGroup>
<AdditionFiles Include="xxxxxxxxxxx\Web.Debug.config;xxxxxxxxx\Web.Release.config">
</AdditionFiles>
<FilesForPackagingFromProject Include="%(AdditionFiles.Identity)">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
完成发布步骤后,您将在发布文件夹中找到这些文件
希望它能对您有所帮助。我使用的是Azure Dev Ops Server,我想在构建时运行版本转换,但也有可能在每个管道目标上运行其他转换。在我的例子中,更改SessionDb连接字符串 我在构建参数中添加了/p:MarkWebConfigAssistFilesAsExclude=false 我将web.Prod.config设置为“始终” 在执行转换时,我仍然收到一个NullReference异常。我不得不搬走
<compilation xdt:Transform="RemoveAttributes(debug)" />
从产品配置转换中删除,因为该属性已随发布配置转换一起删除。l认为您可以参考在Folderprofile.pubxml中添加自定义目标以添加额外文件。@PerryQian MSFT修复成功,谢谢。在探讨这一点的同时,我还研究了如何通过MSBuild WebDeploy中的参数来处理此问题,但这些参数似乎没有起到任何作用-我在下面发布了此示例以供参考-但是,它没有产生任何效果。这在较新版本的MSBuild/Visual Studio中似乎不起作用。在执行上述两个/p值时,Brilliant似乎对我使用MSBuild起到了作用。非常感谢
web.config
web.Debug.config
web.Release.config
<!-- Disable Web.config Transforms -->
<ProfileTransformWebConfigEnabled>false</ProfileTransformWebConfigEnabled>
<MarkWebConfigAssistFilesAsExclude>false</MarkWebConfigAssistFilesAsExclude>
<Target Name="CustomCollectFiles">
<ItemGroup>
<AdditionFiles Include="xxxxxxxxxxx\Web.Debug.config;xxxxxxxxx\Web.Release.config">
</AdditionFiles>
<FilesForPackagingFromProject Include="%(AdditionFiles.Identity)">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<compilation xdt:Transform="RemoveAttributes(debug)" />