diff --git a/.gitignore b/.gitignore index 37ef0f552f5c..507aef8d07fd 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ project.lock.json .builds *.pidb *.log +*.binlog *.scc # Template Manifests generated as part of VSIX build diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets index 2ab644f75673..3fe79f7da911 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets @@ -25,6 +25,21 @@ Copyright (c) .NET Foundation. All rights reserved. To do this, we look at the files that would be copied local when CopyLocalLockFileAssemblies is true --> <_LockFileAssemblies Include="@(AllCopyLocalItems->WithMetadataValue('Type', 'assembly'))" /> + + + + <_RuntimeTargetItems Include="@(_ActiveTFMFileDependencies->WithMetadataValue('FileGroup', 'RuntimeTarget'))" /> + <__RuntimeTargetPublishItems Include="@(FileDefinitions)" Exclude="@(_RuntimeTargetItems)" /> + <_RuntimeTargetPublishItems Include="@(FileDefinitions)" Exclude="@(__RuntimeTargetPublishItems)" /> + + <_LockFileAssemblies Include="@(_RuntimeTargetPublishItems->WithMetadataValue('Type', 'assembly')->'%(ResolvedPath)')"> + false + false + Package + %(PackageName) + %(PackageVersion) + { @@ -138,7 +145,7 @@ public void It_resolves_assembly_conflicts_with_a_NETFramework_library() new XAttribute("Include", "NETStandard.Library"), new XAttribute("Version", "$(BundledNETStandardPackageVersion)"))); - foreach (var dependency in TestAsset.NetStandard1_3Dependencies) + foreach (var dependency in ConflictResolutionAssets.ConflictResolutionDependencies) { itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", dependency.Item1), diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs index 66471486dd5a..23b1a9ecd6c2 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs @@ -153,8 +153,10 @@ public static class Program { public static void Main() { + TestConflictResolution(); Console.WriteLine(""" + outputMessage + @"""); } +" + ConflictResolutionAssets.ConflictResolutionTestMethod + @" } "; var testAsset = _testAssetsManager.CreateTestProject(project, project.Name) @@ -167,7 +169,7 @@ public static void Main() var itemGroup = new XElement(ns + "ItemGroup"); p.Root.Add(itemGroup); - foreach (var dependency in TestAsset.NetStandard1_3Dependencies) + foreach (var dependency in ConflictResolutionAssets.ConflictResolutionDependencies) { itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", dependency.Item1), @@ -216,6 +218,19 @@ public void It_trims_conflicts_from_the_deps_file() IsSdkProject = true }; + project.SourceFiles["Program.cs"] = @" +using System; +public static class Program +{ + public static void Main() + { + TestConflictResolution(); + Console.WriteLine(""Hello, World!""); + } +" + ConflictResolutionAssets.ConflictResolutionTestMethod + @" +} +"; + var testAsset = _testAssetsManager.CreateTestProject(project) .WithProjectChanges(p => { @@ -224,7 +239,7 @@ public void It_trims_conflicts_from_the_deps_file() var itemGroup = new XElement(ns + "ItemGroup"); p.Root.Add(itemGroup); - foreach (var dependency in TestAsset.NetStandard1_3Dependencies) + foreach (var dependency in ConflictResolutionAssets.ConflictResolutionDependencies) { itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", dependency.Item1), diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetStandard2Library.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetStandard2Library.cs index f735c783bc3e..a5065793ed49 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetStandard2Library.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetStandard2Library.cs @@ -51,6 +51,12 @@ public void It_resolves_assembly_conflicts() IsSdkProject = true }; + project.SourceFiles[project.Name + ".cs"] = $@" +using System; +public static class {project.Name} +{{ + {ConflictResolutionAssets.ConflictResolutionTestMethod} +}}"; var testAsset = _testAssetsManager.CreateTestProject(project) .WithProjectChanges(p => @@ -60,7 +66,7 @@ public void It_resolves_assembly_conflicts() var itemGroup = new XElement(ns + "ItemGroup"); p.Root.Add(itemGroup); - foreach (var dependency in TestAsset.NetStandard1_3Dependencies) + foreach (var dependency in ConflictResolutionAssets.ConflictResolutionDependencies) { itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", dependency.Item1), diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs index 04054b8e958c..59eb14bcb91a 100644 --- a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs @@ -224,8 +224,10 @@ public static class Program { public static void Main() { + TestConflictResolution(); Console.WriteLine(""" + outputMessage + @"""); } +" + ConflictResolutionAssets.ConflictResolutionTestMethod + @" } "; var testProjectInstance = _testAssetsManager.CreateTestProject(testProject, testProject.Name) @@ -237,7 +239,7 @@ public static void Main() var itemGroup = new XElement(ns + "ItemGroup"); p.Root.Add(itemGroup); - foreach (var dependency in TestAsset.NetStandard1_3Dependencies) + foreach (var dependency in ConflictResolutionAssets.ConflictResolutionDependencies) { itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", dependency.Item1), diff --git a/test/Microsoft.NET.TestFramework/ConflictResolutionAssets.cs b/test/Microsoft.NET.TestFramework/ConflictResolutionAssets.cs new file mode 100644 index 000000000000..536050f2e120 --- /dev/null +++ b/test/Microsoft.NET.TestFramework/ConflictResolutionAssets.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml.Linq; + +namespace Microsoft.NET.TestFramework +{ + public class ConflictResolutionAssets + { + public static IEnumerable> ConflictResolutionDependencies + { + get + { + string netstandardDependenciesXml = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + + XElement netStandardDependencies = XElement.Parse(netstandardDependenciesXml); + + foreach (var dependency in netStandardDependencies.Elements("dependency")) + { + yield return Tuple.Create(dependency.Attribute("id").Value, dependency.Attribute("version").Value); + } + + yield return Tuple.Create("System.Diagnostics.TraceSource", "4.0.0"); + } + } + + public static string ConflictResolutionTestMethod + { + get + { + return @" + public static void TestConflictResolution() + { + new System.Diagnostics.TraceSource(""ConflictTest""); + }"; + } + } + } +} diff --git a/test/Microsoft.NET.TestFramework/TestAsset.cs b/test/Microsoft.NET.TestFramework/TestAsset.cs index a5d6658620a0..a7d253194291 100644 --- a/test/Microsoft.NET.TestFramework/TestAsset.cs +++ b/test/Microsoft.NET.TestFramework/TestAsset.cs @@ -175,66 +175,5 @@ private bool IsInBinOrObjFolder(string path) return path.Contains(binFolderWithTrailingSlash) || path.Contains(objFolderWithTrailingSlash); } - - public static IEnumerable> NetStandard1_3Dependencies - { - get - { - string netstandardDependenciesXml = @" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "; - - XElement netStandardDependencies = XElement.Parse(netstandardDependenciesXml); - - foreach (var dependency in netStandardDependencies.Elements("dependency")) - { - yield return Tuple.Create(dependency.Attribute("id").Value, dependency.Attribute("version").Value); - } - } - } } }