Skip to content

Commit

Permalink
Set 'BypassFrameworkInstallChecks' MSBuild property when running on Mono
Browse files Browse the repository at this point in the history
'BypassFrameworkInstallChecks' allows builds to skip a particularly hacky check in the GetReferenceAssemblyPaths
task. This hack affects projects that target a .NET Framework version less than 4.0. Essentially, the hack tries
to load a certain assembly from the GAC to "guarantee" that .NET Framework 3.5 SP1 is installed (an old case added
specifically for WPF projects). However, we don't include that assembly in our Mono package. So, many Unity projects
end up failing the check because they often target much early .NET Framework versions. We can fix that by just
skipping the check, which isn't really necessary when we're running on Mono.
  • Loading branch information
DustinCampbell committed Apr 6, 2018
1 parent 357addb commit 11ab9d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ public override ImmutableArray<MSBuildInstance> GetInstances()

var propertyOverrides = ImmutableDictionary.CreateBuilder<string, string>(StringComparer.OrdinalIgnoreCase);

// To better support older versions of Mono that don't include
// MSBuild 15, we attempt to set property overrides to the locations
// of Mono's 'xbuild' and 'xbuild-frameworks' paths.
if (_allowMonoPaths && PlatformHelper.IsMono)
if (PlatformHelper.IsMono)
{
if (TryGetMonoXBuildPath(out var xbuildPath))
// This disables a hack in the "GetReferenceAssemblyPaths" task which attempts
// guarantee that .NET Framework SP1 is installed when the target framework is
// .NET Framework, but the version is less than 4.0. The hack attempts to locate
// a particular assembly in the GAC as a "guarantee". However, we don't include that
// in our Mono package. So, we'll just bypass the check.
propertyOverrides.Add("BypassFrameworkInstallChecks", "true");

// To better support older versions of Mono that don't include
// MSBuild 15, we attempt to set property overrides to the locations
// of Mono's 'xbuild' and 'xbuild-frameworks' paths.
if (_allowMonoPaths)
{
extensionsPath = xbuildPath;
}

if (TryGetMonoXBuildFrameworksPath(out var xbuildFrameworksPath))
{
propertyOverrides.Add("TargetFrameworkRootPath", xbuildFrameworksPath);
if (TryGetMonoXBuildPath(out var xbuildPath))
{
extensionsPath = xbuildPath;
}

if (TryGetMonoXBuildFrameworksPath(out var xbuildFrameworksPath))
{
propertyOverrides.Add("TargetFrameworkRootPath", xbuildFrameworksPath);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.MSBuild/ProjectFile/PropertyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal static class PropertyNames
public const string AssemblyOriginatorKeyFile = nameof(AssemblyOriginatorKeyFile);
public const string BuildProjectReferences = nameof(BuildProjectReferences);
public const string BuildingInsideVisualStudio = nameof(BuildingInsideVisualStudio);
public const string BypassFrameworkInstallChecks = nameof(BypassFrameworkInstallChecks);
public const string Configuration = nameof(Configuration);
public const string CscToolExe = nameof(CscToolExe);
public const string CscToolPath = nameof(CscToolPath);
Expand Down
5 changes: 5 additions & 0 deletions src/OmniSharp.MSBuild/ProjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ private static Dictionary<string, string> CreateGlobalProperties(
globalProperties.AddPropertyOverride(PropertyNames.Configuration, options.Configuration, propertyOverrides, logger);
globalProperties.AddPropertyOverride(PropertyNames.Platform, options.Platform, propertyOverrides, logger);

if (propertyOverrides.TryGetValue(PropertyNames.BypassFrameworkInstallChecks, out var value))
{
globalProperties.Add(PropertyNames.BypassFrameworkInstallChecks, value);
}

return globalProperties;
}

Expand Down

0 comments on commit 11ab9d6

Please sign in to comment.