hoffi/gulp-msbuild

AMD64 MSBuild tools can cause build problems with UWP apps

Opened this issue · 0 comments

I've run into an issue trying to build UWP apps with gulp-msbuild 0.5.4. When attempting to build build a UWP app on an x64 system I receive the following build error.

error MSB3816: Loading assembly "C:\Users\user.nuget\packages\runtime.win7-x86.microsoft.netcore.runtime.coreclr\1.0.2\runtimes\win7-x86\native\mscorlib.ni.dll" failed. System.ArgumentException: A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context. ---> System.BadImageFormatException: Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. An attempt was made to load a program with an incorrect format. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format.

This was reproducible via the command line using the same command that is constructed by the code.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe C:\Projects\test-uwp-app\src\test-uwp-app\test-uwp-app.csproj /target:Restore;Rebuild /verbosity:normal /toolsversion:15.0 /nologo /maxcpucount /property:Configuration=Debug /property:Platform=x86 /property:AppxBundlePlatforms=x86

Removing the amd64 from the path so it would use the x86 tools resolved the issue, and this solution was backed up with this [article from Microsoft](Migrating Your Windows Store App to .NET Native). The relevant information is right at the bottom of the article under Building apps.

Use the x86 build tools that are used by default by Visual Studio. We don't recommend using the AMD64 MSBuild tools, which are found in C:\Program Files (x86)\MSBuild\12.0\bin\amd64; these may create build problems.

Could we get an option that would allow us to specify the tools architecture? I was messing around with this locally and created an option that would allow me to override this, and will probably continue with that so I can get a solution for the short term. In msbuild-finder.js, I've modified lines 164-169 to allow me to override the tools architecture, but it needs some more work before it would be ready to submit.