ASP.Net Core排除发布的语言目录,除了英语。

40

我这样发布我的ASP.Net Core 3.1服务器:

dotnet publish --configuration Release --runtime win7-x64 -p:PublishTrimmed=true --output c:\MyServer

在c:\MyServer目录下,我得到了许多国际语言文件夹:cs、de、es、fr、zh-hans等。

我该如何只发布英文版本?

我尝试在我的csproj中使用ExcludeFoldersFromDeployment

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>    
    <AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>
    <Nullable>enable</Nullable>
    <ExcludeFoldersFromDeployment>cs;de;es;fr;he;hi;it;ja;ko;nl;pl;pt;ru;tr-TR;zh-Hans;zh-Hant</ExcludeFoldersFromDeployment>
  </PropertyGroup>

但那没有帮助

有什么帮助吗?


这个回答解决了你的问题吗? .net core构建会生成本地化文件夹 - Mehdi Dehghani
2个回答

80
编辑你的.csproj文件,在 PropertyGroup 中添加以下行:
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>

它应该仅发布所选语言资源文件夹。


1
请参考MSBuild属性 - https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#satelliteresourcelanguages - shr
这有助于限制语言文件夹的数量,但并不能完全摆脱它们。 - undefined

19

如果您的项目引用了Microsoft.VisualStudio.Web.CodeGeneration.Design,那么在发布输出中会包含许多包含CodeAnalysis.dll文件的语言文件夹,这是脚手架控制器所需的。 如果您的项目符合此条件,请在.csproj文件中更改软件包引用以包括ExcludeAssets="All":

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" ExcludeAssets="All"/>

请参考:https://forums.asp.net/t/2160546.aspx?how+to+get+rid+of+fr+it+ja+etc+folders+in+net+core+3+0+

FYI - 这对我来说可以防止本地化文件夹,但它会破坏脚手架(Core 3.1)。如果我选择使用脚手架构建视图等,则必须删除[ExcludeAssets = All]指令并每次构建项目。 - puddleglum
1
出于某种原因,这对我没有帮助。 - Offir
1
在.NET 7.0中仍然有效。 - Gerard Jaryczewski

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接