Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 4d02ec5

Browse files
committed
[Core] Continue on errors when resolving assembly references
If a PackageReference could not be resolved then no assembly references would be given to the type system from the DotNetProject's GetReferencedAssemblies. Whilst the NuGet restore may fail the project.assets.json file is created and reference information is available. The ResolvePackageAssets target was failing which then stopped the ResolveAssemblyReferencesDesignTime target from being run. Visual Studio on Windows avoids this problem by setting the ContinueOnError property to ErrorAndContinue. This allows all the targets to run even if some of them fail. It also allows references to be returned and provided to the type system service for the PackageReferences that can be determined. Fixes VSTS #998324 - NuGet Package Restore causes BCLs to not be defined/imported
1 parent c1582a7 commit 4d02ec5

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ async Task<List<AssemblyReference>> RunResolveAssemblyReferencesTarget (Configur
11371137
context.LogVerbosity = MSBuildVerbosity.Quiet;
11381138
context.GlobalProperties.SetValue ("Silent", true);
11391139
context.GlobalProperties.SetValue ("DesignTimeBuild", true);
1140+
// Even though some targets may fail it may still be possible for the main resolve targets to return
1141+
// information so we set ContinueOnError. This matches VS on Windows behaviour.
1142+
context.GlobalProperties.SetValue ("ContinueOnError", "ErrorAndContinue");
11401143

11411144
var result = await RunTargetInternal (monitor, "ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime", configuration, context);
11421145
refs = result.Items.Select (i => new AssemblyReference (i.Include, i.Metadata)).ToList ();

main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/ProjectTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,31 @@ public async Task ImplicitlyExpandDesignTimeFacades ()
11081108
}
11091109
}
11101110

1111+
[Test]
1112+
public async Task UnknownNuGetPackageReferenceId_DesignTimeBuilds ()
1113+
{
1114+
FilePath solFile = Util.GetSampleProject ("UnknownPackageReference", "UnknownPackageReference.sln");
1115+
CreateNuGetConfigFile (solFile.ParentDirectory);
1116+
1117+
// Run restore but do not check result since this will fail.
1118+
using var process = Process.Start (new ProcessStartInfo {
1119+
FileName = "nuget",
1120+
Arguments = $"restore -DisableParallelProcessing \"{solFile}\"",
1121+
RedirectStandardError = true,
1122+
RedirectStandardOutput = true,
1123+
UseShellExecute = false
1124+
});
1125+
Assert.IsTrue (process.WaitForExit (120000), "Timeout restoring NuGet packages.");
1126+
1127+
using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile)) {
1128+
var project = sol.GetAllProjects ().Single () as DotNetProject;
1129+
var refs = (await project.GetReferencedAssemblies (ConfigurationSelector.Default)).ToArray ();
1130+
1131+
Assert.IsTrue (refs.Any ());
1132+
Assert.IsTrue (refs.Any (r => r.FilePath.FileName == "Newtonsoft.Json.dll"));
1133+
}
1134+
}
1135+
11111136
/// <summary>
11121137
/// Clear all other package sources and just use the main NuGet package source when
11131138
/// restoring the packages for the project tests.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard1.5</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
9+
<PackageReference Include="UnknownPackageIdThatDoesNotExistAnywhere" Version="1.0.3" />
10+
</ItemGroup>
11+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnknownPackageReference", "UnknownPackageReference.csproj", "{EEC2E74C-F54E-4E9E-B0A6-4E7A0D71A9A9}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{EEC2E74C-F54E-4E9E-B0A6-4E7A0D71A9A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{EEC2E74C-F54E-4E9E-B0A6-4E7A0D71A9A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{EEC2E74C-F54E-4E9E-B0A6-4E7A0D71A9A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{EEC2E74C-F54E-4E9E-B0A6-4E7A0D71A9A9}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
EndGlobal

0 commit comments

Comments
 (0)