I have a .NET 6 project that includes some Exec
nodes, and those commands are failing because (as in this discussion on the msbuild repo) the paths of the generated tmp<blah>.exec.cmd
files are not whitelisted.
The suggested fix in there is
The location of this file is controlled by the environment variable
TEMP
. Can you set that to a custom value before invoking MSBuild?
Which I'm sure would work - but I don't know how to do that. According to this question (which is for C++ not C#, but it's the best I can find) you can use EnvironmentVariables="<blah>"
in that same node, but the files are still generated in %LOCALAPPDATA% despite my trying to set TEMP
to something else. A failing example is below - what am I doing wrong?
<Target Name="ToolRestore" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet tool restore" StandardOutputImportance="high" EnvironmentVariables="TEMP=C:\MSBuildTemp" />
</Target>
An answer should ideally be valid for building/debugging in Visual Studio and via dotnet build/test/publish
. Even better would be a method of making the value of TEMP
be variable per-user, but that's not necessary.