Msbuild: How can I build a .NET Core project against custom locales using msbuild?

Created on 24 Jul 2017  路  6Comments  路  Source: dotnet/msbuild

I want to build *.resx for locale that platform does not support in default. With the help of @tarekgh and @jefgen I installed custom locale on windows, and I succeeded in building <custom-locale>.resx with VS2017 (https://github.com/dotnet/corefx/issues/22135).

Now I need to build it on linux using dotnet cli.

Looking at the msbuild code quickly, https://github.com/Microsoft/msbuild/blob/master/src/Tasks/CultureInfoCache.cs#L31, it seems that msbuild currently only uses the hardcoded locale names for coreclr.

How can we solve this situation?

In my guess, the simplest way is to (a) add all the locales I need to the cache, and the other way is (b) to make msbuild to get the locale information from the platform for coreclr as well. But, to do so, it is likely that msbuild should be modified to target the netstandard2.0.

Is my guess right? Which way would be better?

Most helpful comment

@rainersigwald is it possible using item list which can be provided by the projects and get appended to the culture name list?

for example, the csproj will contain:

    <ItemGroup>  
        <AdditionalCultures Include = "tu-IN" />  
        <AdditionalCultures Include = "sat-IN" />  
        <AdditionalCultures Include = "mai-IN" />  
    </ItemGroup> 

and you'll honor this list in addition to the hard coded list

All 6 comments

In net core 2.0, we support CultureInfo.GetCultures. so the code

http://index/?query=CultureInfoCache.cs&rightProject=Microsoft.Build.Tasks.Core&file=CultureInfoCache.cs&line=26

Should always use CultureInfo.GetCultures and get rid of the hard coded cultures list.

We can adopt that once we're on .NET Standard 2.0. Until then, I'm not sure what's best.

cc @cdmihai

@rainersigwald is it possible using item list which can be provided by the projects and get appended to the culture name list?

for example, the csproj will contain:

    <ItemGroup>  
        <AdditionalCultures Include = "tu-IN" />  
        <AdditionalCultures Include = "sat-IN" />  
        <AdditionalCultures Include = "mai-IN" />  
    </ItemGroup> 

and you'll honor this list in addition to the hard coded list

Discussed this in out team standup. We prefer getting the OS supported list of cultures via CultureInfo.GetCultures. We've set the milestone for the next VS foundation update. If we manage to get .net core msbuild on netstandard 2.0 by then, we'll just call the method, and if not, we'll use reflection since the CLI uses ns2.0 either way.

Thank you for updating the progress @cdmihai .

If we manage to get .net core msbuild on netstandard 2.0 by then, we'll just call the method, and if not, we'll use reflection since the CLI uses ns2.0 either way.

But, I do not fully understand how the being CLI uses netstandard 2.0 is related to msbuild can use CultureInfo.GetCultures. Is the CLI means the .NET Core CLI? which invokes msbuild?

By the way, after the next VS foundation update, can msbuild on .NET Core CLI also expect to get locale information using CultureInfo.GetCultures regardless of running platform, including Linux and macOS?

But, I do not fully understand how the being CLI uses netstandard 2.0 is related to msbuild can use CultureInfo.GetCultures. Is the CLI means the .NET Core CLI? which invokes msbuild?

As far as I know, dotnet CLI swaps msbuild's runtime.json with something that targets the 2.0 framework. So even though MSBuild does not get compiled against 2.0, it gets to run against it (not the safest thing but it seems to work ...). Meaning we could use reflection to find CultureInfo.GetCultures. We'll still have to define what happens when GetCultures is not there. But hopefully we'll get MSBuild on ns2.0 and not require reflection.

By the way, after the next VS foundation update, can msbuild on .NET Core CLI also expect to get locale information using聽CultureInfo.GetCultures聽regardless of running platform, including Linux and macOS?

That's the plan, because 2.0 and beyond would expose the GetCultures API on the supported platforms.

Was this page helpful?
0 / 5 - 0 ratings