0

How can I, through the .csproj file, specify environment variables to apply during the build, such as when building with Rider?

Specifically, I want to set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 so that I can build from within the IDE, without resorting to the command line (see below).

Adding <InvariantGlobalization>true</InvariantGlobalization> to the project file did not work, since that does not affect the underlying/imported build target, but executing export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 before dotnet build NAME.csproj worked.

Background: A recent distro upgrade on openSuse Tumbleweed bricked MonoGame project builds with the following error message when invoking mgcb (re-installing ICU with Zypper did not fix the issue):

Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.
(...)
error MSB3073: The command "dotnet (...) exited with code 134

Edit: I have finally gotten a Target to run before the Nopipeline target using InitialTargets. The problem now is the Exec task runs in a discarded scope.

Cecil Dishwasher
  • 364
  • 2
  • 15
  • The error line is not that useful without context, so which target ran a dotnet-based tool. For tool invocations using things like an `` task, the target author could set environment variables – Martin Ullrich Jun 07 '22 at 12:22

1 Answers1

0

Depending on which task fails, you can hope that the target author added an option to set the environment variables.

E.g. for C# compilation, you could set:

<PropertyGroup>
  <CscEnvironment>$(CscEnvironment);DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1</CscEnvironment>
</PropertyGroup>

If the tool is run by a custom target, you would need to author a replacement target that allows setting the environment variable.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217