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

Commit 77025be

Browse files
committed
[DotNetCore] Continue on error when finding framework references
Handle other MSBuild targets failing when calling the MSBuild target ResolveFrameworkReferences by setting ContinueOnError to ErrorAndContinue. Previously if there was any other failure the design time build would stop even though the main msbuild target may work and return some references.
1 parent 62b3b46 commit 77025be

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,9 @@ async Task<List<FrameworkReference>> RunResolveFrameworkReferencesTarget (Config
12731273
context.BuilderQueue = BuilderQueue.ShortOperations;
12741274
context.LoadReferencedProjects = false;
12751275
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");
12761279

12771280
var result = await RunTargetInternal (monitor, "ResolveFrameworkReferences", configuration, context);
12781281

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

0 commit comments

Comments
 (0)