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

Commit c1e35b5

Browse files
authored
Merge pull request #8896 from mono/design-time-builds-continue-on-error
[Core] Continue on errors when resolving assembly references
2 parents e4eb6b0 + 77025be commit c1e35b5

File tree

8 files changed

+162
-0
lines changed

8 files changed

+162
-0
lines changed

main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<Compile Include="MonoDevelop.DotNetCore.Tests\TestableFrameworkReferencesNodeBuilder.cs" />
4242
<Compile Include="MonoDevelop.DotNetCore.Tests\FakeUpdatedPackagesInWorkspace.cs" />
4343
<Compile Include="MonoDevelop.DotNetCore.Tests\PackProjectTests.cs" />
44+
<Compile Include="MonoDevelop.DotNetCore.Tests\FrameworkReferenceTests.cs" />
4445
</ItemGroup>
4546
<ItemGroup>
4647
<ProjectReference Include="..\..\..\..\external\guiunit\src\framework\GuiUnit_NET_4_5.csproj">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// FrameworkReferenceTests.cs
3+
//
4+
// Author:
5+
// Matt Ward <[email protected]>
6+
//
7+
// Copyright (c) 2019 Microsoft Corporation
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
27+
using System.Diagnostics;
28+
using System.Linq;
29+
using System.Threading;
30+
using System.Threading.Tasks;
31+
using MonoDevelop.Core;
32+
using MonoDevelop.Projects;
33+
using NUnit.Framework;
34+
using UnitTests;
35+
36+
namespace MonoDevelop.DotNetCore.Tests
37+
{
38+
[TestFixture]
39+
class FrameworkReferenceTests : DotNetCoreTestBase
40+
{
41+
static bool IsDotNetCoreSdk30OrLaterInstalled ()
42+
{
43+
return DotNetCoreSdk.Versions.Any (version => version.Major >= 3);
44+
}
45+
46+
[Test]
47+
public async Task UnknownNuGetPackageReferenceId_DesignTimeBuilds ()
48+
{
49+
if (!IsDotNetCoreSdk30OrLaterInstalled ()) {
50+
Assert.Ignore (".NET Core 3 SDK is not installed.");
51+
}
52+
53+
FilePath solutionFileName = Util.GetSampleProject ("UnknownPackageReference", "NetStandard21.sln");
54+
CreateNuGetConfigFile (solutionFileName.ParentDirectory);
55+
56+
// Run restore but do not check result since this will fail.
57+
var process = Process.Start ("msbuild", $"/t:Restore /p:RestoreDisableParallel=true \"{solutionFileName}\"");
58+
Assert.IsTrue (process.WaitForExit (120000), "Timeout restoring NuGet packages.");
59+
60+
using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFileName)) {
61+
var project = sol.GetAllProjects ().Single () as DotNetProject;
62+
var references = (await project.GetFrameworkReferences (ConfigurationSelector.Default, CancellationToken.None)).ToArray ();
63+
64+
Assert.IsTrue (references.Any ());
65+
Assert.IsTrue (references.Any (r => r.Include == "NETStandard.Library"));
66+
}
67+
}
68+
}
69+
}

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

Lines changed: 9 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 ();
@@ -1198,6 +1201,9 @@ async Task<List<PackageDependency>> RunResolvePackageDependenciesTarget (Configu
11981201
context.BuilderQueue = BuilderQueue.ShortOperations;
11991202
context.LoadReferencedProjects = false;
12001203
context.LogVerbosity = MSBuildVerbosity.Quiet;
1204+
// Even though some targets may fail it may still be possible for the main resolve target to return
1205+
// information so we set ContinueOnError. This matches VS on Windows behaviour.
1206+
context.GlobalProperties.SetValue ("ContinueOnError", "ErrorAndContinue");
12011207

12021208
var result = await RunTargetInternal (monitor, "ResolvePackageDependenciesDesignTime", configuration, context);
12031209

@@ -1267,6 +1273,9 @@ async Task<List<FrameworkReference>> RunResolveFrameworkReferencesTarget (Config
12671273
context.BuilderQueue = BuilderQueue.ShortOperations;
12681274
context.LoadReferencedProjects = false;
12691275
context.LogVerbosity = MSBuildVerbosity.Quiet;
1276+
// Even though some targets may fail it may still be possible for the main resolve target to return
1277+
// information so we set ContinueOnError. This matches VS on Windows behaviour.
1278+
context.GlobalProperties.SetValue ("ContinueOnError", "ErrorAndContinue");
12701279

12711280
var result = await RunTargetInternal (monitor, "ResolveFrameworkReferences", configuration, context);
12721281

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,34 @@ 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 references = (await project.GetReferencedAssemblies (ConfigurationSelector.Default)).ToArray ();
1130+
var packageDependencies = (await project.GetPackageDependencies (ConfigurationSelector.Default, CancellationToken.None)).ToArray ();
1131+
1132+
Assert.IsTrue (references.Any ());
1133+
Assert.IsTrue (references.Any (r => r.FilePath.FileName == "Newtonsoft.Json.dll"));
1134+
Assert.IsTrue (packageDependencies.Any ());
1135+
Assert.IsTrue (packageDependencies.Any (p => p.Name == "Newtonsoft.Json"));
1136+
}
1137+
}
1138+
11111139
/// <summary>
11121140
/// Clear all other package sources and just use the main NuGet package source when
11131141
/// restoring the packages for the project tests.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="UnknownPackageIdThatDoesNotExistAnywhere" Version="1.0.3" />
9+
</ItemGroup>
10+
</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}") = "NetStandard21", "NetStandard21.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
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)