You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Azure DevOps第二个.NET Framework构建步骤以输出resx资源文件?

.NET Framework构建制品缺失Resources文件夹的解决办法

问题详情

我有两个.NET Framework解决方案,均包含\Resources文件夹,存放strings.cs-CZ.resx格式的资源文件,但构建结果存在差异:

第一个解决方案(正常输出资源文件)

使用Azure DevOps的Visual Studio Build步骤,MSBuild参数如下:

/p:DeployOnBuild=true /p:PackageLocation="$(build.artifactstagingdirectory)\\" /p:PublishProfile="$(build.sourcesdirectory)\App.Api\Properties\PublishProfiles\VSTS-InPlacePublish.pubxml"

构建生成的制品包含完整的\Resources文件夹及所有resx文件。该方案包含\App.Api\Properties\PublishProfiles\VSTS-InPlacePublish.pubxml文件,内容为:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>vsts-publish</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
  </PropertyGroup>
</Project>

第二个解决方案(缺失资源文件)

同样使用Azure DevOps的Visual Studio Build步骤,MSBuild参数如下:

/p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactstagingdirectory)\\App\\"

构建生成的制品完全没有\Resources文件夹及resx文件,且该方案没有对应的pubxml文件。

解决方法

可以通过两种方式让第二个方案输出资源文件:

方式1:添加Publish Profile文件

在第二个解决方案的对应项目下创建Properties\PublishProfiles\VSTS-InPlacePublish.pubxml文件,内容与第一个方案的pubxml完全一致。然后修改MSBuild参数,添加/p:PublishProfile指向该文件,调整后的参数为:

/p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactstagingdirectory)\\App\\" /p:PublishProfile="$(build.sourcesdirectory)\[项目名]\Properties\PublishProfiles\VSTS-InPlacePublish.pubxml"

(替换[项目名]为实际项目名称)

方式2:直接通过MSBuild参数传递关键属性

无需创建pubxml文件,直接在现有MSBuild参数中添加DeleteExistingFiles=False属性,修改后的参数为:

/p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactstagingdirectory)\\App\\" /p:DeleteExistingFiles=False

核心原因是第一个方案的pubxml中设置了DeleteExistingFiles=False,而第二个方案默认启用了文件清理逻辑,导致资源文件被排除。添加该参数后,构建过程不会删除已生成的资源文件,从而保留\Resources文件夹。


内容的提问来源于stack exchange,提问作者Matt W

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 05:35:08