Skip to content

Commit

Permalink
build.cake: make sure to use the last MSBuild version
Browse files Browse the repository at this point in the history
Somehow, cake was defaulting to use the old MSBuild (whole path
being `C:/windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe`)
instead of the one in the VS2019 folder (which should be in
`%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe`
but is better to be located via vswhere).

This fixes many build problems happening in the GitHubActions VM:

```
"D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\ZXing.Net.Mobile.sln" (Build target) (1) ->
"D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\Source\ZXing.Net.Mobile.Android\ZXing.Net.Mobile.Android.csproj" (default target) (5) ->
  D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\Source\ZXing.Net.Mobile.Android\ZXing.Net.Mobile.Android.csproj(82,60): error MSB4066: The attribute "Version" in element <PackageReference> is unrecognized.

"D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\ZXing.Net.Mobile.sln" (Build target) (1) ->
"D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\Source\ZXing.Net.Mobile.iOS\ZXing.Net.Mobile.iOS.csproj" (default target) (6) ->
  D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\Source\ZXing.Net.Mobile.iOS\ZXing.Net.Mobile.iOS.csproj(72,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

"D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\ZXing.Net.Mobile.sln" (Build target) (1) ->
"D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\Source\ZXing.Net.Mobile.WindowsUniversal\ZXing.Net.Mobile.WindowsUniversal.csproj" (default target) (7) ->
  D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\Source\ZXing.Net.Mobile.WindowsUniversal\ZXing.Net.Mobile.WindowsUniversal.csproj(155,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v11.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
```

Solution taken from https://stackoverflow.com/a/45251462/544947
Hint taken from https://stackoverflow.com/a/55269143/544947
  • Loading branch information
knocte committed Oct 6, 2019
1 parent df7f804 commit 1a95f0e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#tool nuget:?package=XamarinComponent
#tool nuget:?package=vswhere

#addin nuget:?package=Cake.Android.SdkManager
#addin nuget:?package=Cake.XCode
Expand Down Expand Up @@ -41,9 +42,20 @@ Task("libs")
NuGetRestore("./ZXing.Net.Mobile.sln");
NuGetRestore("./ZXing.Net.Mobile.Forms.sln");
DirectoryPath vsLatest = VSWhereLatest();
string msbuildExeRelativePath = "./MSBuild/Current/Bin/MSBuild.exe";
FilePath msbuildPathFromVS = (vsLatest == null) ? null : vsLatest.CombineWithFilePath(msbuildExeRelativePath);
var config = IsRunningOnWindows() ? "ReleaseWin" : "ReleaseMac";
MSBuild ("./ZXing.Net.Mobile.sln", c => c.SetConfiguration(config).SetMSBuildPlatform(MSBuildPlatform.x86));
MSBuild ("./ZXing.Net.Mobile.Forms.sln", c => c.SetConfiguration(config).SetMSBuildPlatform(MSBuildPlatform.x86));
var msbuildSettings = new MSBuildSettings {
Configuration = config,
MSBuildPlatform = MSBuildPlatform.x86,
ToolPath = msbuildPathFromVS,
};
MSBuild ("./ZXing.Net.Mobile.sln", msbuildSettings);
MSBuild ("./ZXing.Net.Mobile.Forms.sln", msbuildSettings);
});

Task ("samples")
Expand Down

0 comments on commit 1a95f0e

Please sign in to comment.