2

默认情况下,使用 MSBuild/Visual Studio 发布 Web 项目时,会应用配置转换。

我想在输出中包含配置转换。

输入

web.config  
web.Debug.config   
web.Release.config  

默认输出

web.config

期望的输出

web.config  
web.Debug.config   
web.Release.config  
4

3 回答 3

2

使用 Visual Studio将文件构建操作更新为内容(例如右键单击、属性)

在此处输入图像描述

发布任务仍会转换文件,因此我们需要告诉 MSBuild,我们不想在发布时转换这些文件。

这可以通过将以下参数传递到 MSBuild 中来实现:

/p:ProfileTransformWebConfigEnabled=false /p:MarkWebConfigAssistFilesAsExclude=false

如果您在 Visual Studio 中工作,您可以通过将这些属性添加到文件夹发布配置文件来测试此行为 PublishProfile.xml

<!-- Disable Web.config Transforms -->
<ProfileTransformWebConfigEnabled>false</ProfileTransformWebConfigEnabled>
<MarkWebConfigAssistFilesAsExclude>false</MarkWebConfigAssistFilesAsExclude>
于 2020-01-09T16:53:20.740 回答
2

在 Web 部署输出中包含 web.release.config

默认情况下,在发布网站时,VS 不打包web.debug.configweb.release.config而只打包web.config.

为了实现你想要的,你可以添加一个自定义目标publishprofile.pubxml来包含这些额外的文件。

请试试这个:

<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>

完成发布步骤后,您将在 Publish 文件夹中找到这些文件。

希望它可以帮助你。

于 2020-01-10T08:24:24.913 回答
0

我使用的是 Azure Dev Ops Server,我想在构建时运行发布转换,但也有可能为每个管道目标运行额外的转换。在我的情况下更改 SessionDb 连接字符串

我添加/p:MarkWebConfigAssistFilesAsExclude=false到构建参数

我设置web.Prod.config<CopyToOutputDirectory>Always</CopyToOutputDirectory>

进行转换时,我仍然收到 NullReference 异常。我不得不删除

<compilation xdt:Transform="RemoveAttributes(debug)" />

从 prod 配置转换中删除,因为该属性已通过发布配置转换删除。

于 2020-12-01T20:12:40.350 回答