-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deps.json should include project references that aren't present in project.assets.json #28963
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
457feac
Initial change to try to get project references that are not a part o…
wrall 19e3a8f
PR feedback
wrall 71d5b2c
PR comment fixes, fix to problematic update
wrall 98714fa
fix test again
wrall e46be67
Add a property that controls whether to use the new behavior or not
wrall 8130e1c
PR feedback - move default property setting to Microsoft.NET.Sdk.targets
wrall 14fdc00
Enable new behavior by default as per PR feedback
wrall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
...s/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithTransitiveNonSdkProjectRefs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
|
||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyModel; | ||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.Commands; | ||
using Microsoft.NET.TestFramework.ProjectConstruction; | ||
|
||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.NET.Build.Tests | ||
{ | ||
public class GivenThatWeWantToBuildAnAppWithTransitiveNonSdkProjectRefs : SdkTest | ||
{ | ||
public GivenThatWeWantToBuildAnAppWithTransitiveNonSdkProjectRefs(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
[WindowsOnlyFact] | ||
public void It_builds_the_project_successfully() | ||
{ | ||
// NOTE the projects created by CreateTestProject: | ||
// TestApp --depends on--> MainLibrary --depends on--> AuxLibrary (non-SDK) | ||
// (TestApp transitively depends on AuxLibrary) | ||
var testAsset = _testAssetsManager | ||
.CreateTestProject(CreateTestProject()); | ||
|
||
VerifyAppBuilds(testAsset, string.Empty); | ||
} | ||
|
||
[WindowsOnlyTheory] | ||
[InlineData("")] | ||
[InlineData("TestApp.")] | ||
public void It_builds_deps_correctly_when_projects_do_not_get_restored(string prefix) | ||
{ | ||
// NOTE the projects created by CreateTestProject: | ||
// TestApp --depends on--> MainLibrary --depends on--> AuxLibrary | ||
// (TestApp transitively depends on AuxLibrary) | ||
var testAsset = _testAssetsManager | ||
.CreateTestProject(CreateTestProject()) | ||
.WithProjectChanges( | ||
(projectName, project) => | ||
{ | ||
string projectFileName = Path.GetFileNameWithoutExtension(projectName); | ||
if (StringComparer.OrdinalIgnoreCase.Equals(projectFileName, "AuxLibrary") || | ||
StringComparer.OrdinalIgnoreCase.Equals(projectFileName, "MainLibrary")) | ||
{ | ||
var ns = project.Root.Name.Namespace; | ||
|
||
if (!string.IsNullOrEmpty(prefix)) | ||
{ | ||
XElement propertyGroup = project.Root.Element(XName.Get("PropertyGroup", ns.NamespaceName)); | ||
XElement assemblyName = propertyGroup.Element(XName.Get("AssemblyName", ns.NamespaceName)); | ||
wrall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assemblyName.RemoveAll(); | ||
assemblyName.Add("TestApp." + projectFileName); | ||
wrall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// indicate that project restore is not supported for these projects: | ||
var target = new XElement(ns + "Target", | ||
new XAttribute("Name", "_IsProjectRestoreSupported"), | ||
new XAttribute("Returns", "@(_ValidProjectsForRestore)")); | ||
|
||
project.Root.Add(target); | ||
} | ||
}); | ||
|
||
string outputDirectory = VerifyAppBuilds(testAsset, prefix); | ||
|
||
using (var depsJsonFileStream = File.OpenRead(Path.Combine(outputDirectory, "TestApp.deps.json"))) | ||
{ | ||
var dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream); | ||
|
||
var projectNames = dependencyContext.RuntimeLibraries.Select(library => library.Name).ToList(); | ||
projectNames.Should().BeEquivalentTo(new[] { "TestApp", prefix + "AuxLibrary", prefix + "MainLibrary" }); | ||
} | ||
} | ||
|
||
private TestProject CreateTestProject() | ||
{ | ||
string targetFrameworkVersion = "v4.8"; | ||
|
||
var auxLibraryProject = new TestProject("AuxLibrary") | ||
{ | ||
IsSdkProject = false, | ||
TargetFrameworkVersion = targetFrameworkVersion | ||
}; | ||
auxLibraryProject.SourceFiles["Helper.cs"] = """ | ||
using System; | ||
|
||
namespace AuxLibrary | ||
{ | ||
public static class Helper | ||
{ | ||
public static void WriteMessage() | ||
{ | ||
Console.WriteLine("This string came from AuxLibrary!"); | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
var mainLibraryProject = new TestProject("MainLibrary") | ||
{ | ||
IsSdkProject = false, | ||
TargetFrameworkVersion = targetFrameworkVersion | ||
}; | ||
mainLibraryProject.ReferencedProjects.Add(auxLibraryProject); | ||
mainLibraryProject.SourceFiles["Helper.cs"] = """ | ||
using System; | ||
|
||
namespace MainLibrary | ||
{ | ||
public static class Helper | ||
{ | ||
public static void WriteMessage() | ||
{ | ||
Console.WriteLine("This string came from MainLibrary!"); | ||
AuxLibrary.Helper.WriteMessage(); | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
var testAppProject = new TestProject("TestApp") | ||
{ | ||
IsExe = true, | ||
TargetFrameworks = ToolsetInfo.CurrentTargetFramework | ||
}; | ||
testAppProject.AdditionalProperties["ProduceReferenceAssembly"] = "false"; | ||
testAppProject.ReferencedProjects.Add(mainLibraryProject); | ||
testAppProject.SourceFiles["Program.cs"] = """ | ||
using System; | ||
|
||
namespace TestApp | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Console.WriteLine("TestApp --depends on--> MainLibrary --depends on--> AuxLibrary"); | ||
MainLibrary.Helper.WriteMessage(); | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
return testAppProject; | ||
} | ||
|
||
private string VerifyAppBuilds(TestAsset testAsset, string prefix) | ||
{ | ||
var buildCommand = new BuildCommand(testAsset, "TestApp"); | ||
var outputDirectory = buildCommand.GetOutputDirectory(ToolsetInfo.CurrentTargetFramework); | ||
|
||
buildCommand | ||
.Execute() | ||
.Should() | ||
.Pass(); | ||
|
||
outputDirectory.Should().OnlyHaveFiles(new[] { | ||
"TestApp.dll", | ||
"TestApp.pdb", | ||
$"TestApp{EnvironmentInfo.ExecutableExtension}", | ||
"TestApp.deps.json", | ||
"TestApp.runtimeconfig.json", | ||
prefix + "MainLibrary.dll", | ||
prefix + "MainLibrary.pdb", | ||
prefix + "AuxLibrary.dll", | ||
prefix + "AuxLibrary.pdb", | ||
}); | ||
|
||
new DotnetCommand(Log, Path.Combine(outputDirectory.FullName, "TestApp.dll")) | ||
.Execute() | ||
.Should() | ||
.Pass() | ||
.And | ||
.HaveStdOutContaining("This string came from MainLibrary!") | ||
.And | ||
.HaveStdOutContaining("This string came from AuxLibrary!"); | ||
|
||
return outputDirectory.FullName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under what conditions would this be null or empty, and should we be returning true here?