From 986625aa9cbd4ac671bb30a065f049793cd1084e Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Mon, 26 Mar 2018 17:30:42 -0700 Subject: [PATCH 1/9] Add MSBuildAllProjects to GenerateBuildDependencyFile target inputs Fixes #1942 (in most cases) --- .../Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 797ce5df73af..0a28d2cf517c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -118,7 +118,7 @@ Copyright (c) .NET Foundation. All rights reserved. _ComputeReferenceAssemblies" BeforeTargets="CopyFilesToOutputDirectory" Condition=" '$(GenerateDependencyFile)' == 'true'" - Inputs="$(ProjectAssetsFile)" + Inputs="$(ProjectAssetsFile);$(MSBuildAllProjects)" Outputs="$(ProjectDepsFilePath)"> + From 7621a254a491f0c63d5849df32bc7b13588223ae Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 4 Apr 2018 18:37:57 -0700 Subject: [PATCH 3/9] Add tests for file and assembly versions in deps file --- ...DepsJsonShouldContainVersionInformation.cs | 136 ++++++++++++++++++ .../Microsoft.NET.Publish.Tests.csproj | 1 + 2 files changed, 137 insertions(+) create mode 100644 src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs new file mode 100644 index 000000000000..05f93457b9ac --- /dev/null +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +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.Publish.Tests +{ + public class GivenThatAPublishedDepsJsonShouldContainVersionInformation : SdkTest + { + public GivenThatAPublishedDepsJsonShouldContainVersionInformation(ITestOutputHelper log) : base(log) + { + } + + private TestProject GetTestProject() + { + var testProject = new TestProject() + { + Name = "DepsJsonVersions", + TargetFrameworks = "netcoreapp2.0", + IsSdkProject = true, + IsExe = true, + }; + testProject.PackageReferences.Add(new TestPackageReference("System.Collections.Immutable", "1.5.0-preview1-26216-02")); + testProject.PackageReferences.Add(new TestPackageReference("Libuv", "1.10.0")); + + return testProject; + } + + [Fact] + public void Versions_are_included_in_deps_json() + { + var testProject = GetTestProject(); + + var testAsset = _testAssetsManager.CreateTestProject(testProject) + .Restore(Log, testProject.Name); + + var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + + publishCommand.Execute() + .Should() + .Pass(); + + var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier); + publishDirectory.Should().HaveFile(testProject.Name + ".deps.json"); + + DependencyContext dependencyContext; + using (var depsJsonFileStream = File.OpenRead(Path.Combine(publishDirectory.FullName, $"{testProject.Name}.deps.json"))) + { + dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream); + } + + var libuvRuntimeLibrary = dependencyContext.RuntimeLibraries.Single(l => l.Name == "Libuv"); + var libuvRuntimeFiles = libuvRuntimeLibrary.NativeLibraryGroups.SelectMany(rag => rag.RuntimeFiles).ToList(); + libuvRuntimeFiles.Should().NotBeEmpty(); + foreach (var runtimeFile in libuvRuntimeFiles) + { + runtimeFile.AssemblyVersion.Should().BeNull(); + runtimeFile.FileVersion.Should().Be("0.0.0.0"); + } + + var immutableRuntimeLibrary = dependencyContext.RuntimeLibraries.Single(l => l.Name == "System.Collections.Immutable"); + var immutableRuntimeFiles = immutableRuntimeLibrary.RuntimeAssemblyGroups.SelectMany(rag => rag.RuntimeFiles).ToList(); + immutableRuntimeFiles.Should().NotBeEmpty(); + foreach (var runtimeFile in immutableRuntimeFiles) + { + runtimeFile.AssemblyVersion.Should().Be("1.2.3.0"); + runtimeFile.FileVersion.Should().Be("4.6.26216.2"); + } + } + + [Fact] + public void Versions_are_not_included_for_self_contained_apps() + { + Versions_are_not_included(false); + } + + [Fact] + public void Versions_are_not_included_for_build() + { + Versions_are_not_included(true); + } + + private void Versions_are_not_included(bool build, [CallerMemberName] string callingMethod = "") + { + var testProject = GetTestProject(); + testProject.RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid(testProject.TargetFrameworks); + + var testAsset = _testAssetsManager.CreateTestProject(testProject, callingMethod) + .Restore(Log, testProject.Name); + + MSBuildCommand command; + if (build) + { + command = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + } + else + { + command = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + } + + command.Execute() + .Should() + .Pass(); + + var outputDirectory = command.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier); + outputDirectory.Should().HaveFile(testProject.Name + ".deps.json"); + + DependencyContext dependencyContext; + using (var depsJsonFileStream = File.OpenRead(Path.Combine(outputDirectory.FullName, $"{testProject.Name}.deps.json"))) + { + dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream); + } + + var allRuntimeFiles = dependencyContext.RuntimeLibraries.SelectMany(rl => rl.NativeLibraryGroups.Concat(rl.RuntimeAssemblyGroups)) + .SelectMany(rag => rag.RuntimeFiles); + + allRuntimeFiles.Should().NotBeEmpty(); + + foreach (var runtimeFile in allRuntimeFiles) + { + runtimeFile.AssemblyVersion.Should().BeNull(); + runtimeFile.FileVersion.Should().BeNull(); + } + } + } +} diff --git a/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj b/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj index 227ae3981a70..43ec75dcd6db 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj +++ b/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj @@ -21,6 +21,7 @@ + From c813fb47c8403234627af2bbdb1a14efab7cc5ee Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 5 Apr 2018 23:05:50 -0700 Subject: [PATCH 4/9] Add test for roll-forward assembly-loading behavior --- ...DepsJsonShouldContainVersionInformation.cs | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs index 05f93457b9ac..b3407498bb93 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs @@ -5,6 +5,7 @@ using System.Runtime.CompilerServices; using System.Text; using FluentAssertions; +using Microsoft.DotNet.Cli.Utils; using Microsoft.Extensions.DependencyModel; using Microsoft.NET.TestFramework; using Microsoft.NET.TestFramework.Assertions; @@ -132,5 +133,92 @@ private void Versions_are_not_included(bool build, [CallerMemberName] string cal runtimeFile.FileVersion.Should().BeNull(); } } + + [Fact] + public void Inbox_version_of_assembly_is_loaded_over_applocal_version() + { + var testProject = GetTestProject(); + + testProject.SourceFiles["Program.cs"] = @" +using System; + +static class Program +{ + public static void Main() + { + Console.WriteLine(typeof(object).Assembly.Location); + Console.WriteLine(typeof(System.Collections.Immutable.ImmutableList).Assembly.Location); + } +} +"; + + var testAsset = _testAssetsManager.CreateTestProject(testProject) + .Restore(Log, testProject.Name); + + var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + + publishCommand.Execute() + .Should() + .Pass(); + + var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier); + + + // Assembly from package should be deployed, as it is newer than the in-box version for netcoreapp2.0, + // which is what the app targets + publishDirectory.Should().HaveFile("System.Collections.Immutable.dll"); + + var exePath = Path.Combine(publishDirectory.FullName, testProject.Name + ".dll"); + + // We want to test a .NET Core 2.0 app rolling forward to .NET Core 2.1. + // This wouldn't happen in our test environment as we also have the .NET Core 2.0 shared + // framework installed. So we get the RuntimeFrameworkVersion of an app + // that targets .NET Core 2.1, and then use the --fx-version parameter to the host + // to force the .NET Core 2.0 app to run on that version + string rollForwardVersion = GetRollForwardNetCoreAppVersion(); + + var foo = TestContext.Current.ToolsetUnderTest.CliVersionForBundledVersions; + var runAppCommand = Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, + new string[] { "exec", "--fx-version", rollForwardVersion, exePath }); + + var runAppResult = runAppCommand + .CaptureStdOut() + .CaptureStdErr() + .Execute(); + + runAppResult + .Should() + .Pass(); + + var stdOutLines = runAppResult.StdOut.Split(Environment.NewLine); + + string coreDir = Path.GetDirectoryName(stdOutLines[0]); + string immutableDir = Path.GetDirectoryName(stdOutLines[1]); + + immutableDir.Should().BeEquivalentTo(coreDir, "immutable collections library from Framework should win"); + + } + + string GetRollForwardNetCoreAppVersion() + { + var testProject = new TestProject() + { + Name = nameof(GetRollForwardNetCoreAppVersion), + TargetFrameworks = "netcoreapp2.1", + IsSdkProject = true, + IsExe = true + }; + var testAsset = _testAssetsManager.CreateTestProject(testProject) + .Restore(Log, testProject.Name); + var getValuesCommand = new GetValuesCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name), + testProject.TargetFrameworks, "RuntimeFrameworkVersion") + { + ShouldCompile = false + }; + + getValuesCommand.Execute().Should().Pass(); + + return getValuesCommand.GetValues().Single(); + } } } From 484df50210c4acfbe58ed68d85940eeaed3e2779 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Mon, 9 Apr 2018 09:28:55 -0700 Subject: [PATCH 5/9] Allow projects to opt in or out of including runtime file versions in deps.json --- .../Microsoft.NET.Build.Tasks/GenerateDepsFile.cs | 10 ++-------- .../targets/Microsoft.NET.Publish.targets | 9 ++++++++- .../targets/Microsoft.NET.Sdk.targets | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs index 53430378312f..d9888e76df94 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs @@ -73,7 +73,7 @@ public class GenerateDepsFile : TaskBase public bool IsSelfContained { get; set; } - public bool IsPublish { get; set; } + public bool IncludeRuntimeFileVersions { get; set; } List _filesWritten = new List(); @@ -140,13 +140,7 @@ protected override void ExecuteCore() PlatformLibraryName, IsSelfContained); - // If publishing a framework-dependent app, then include the assembly and file versions of files in the - // deps.json to support rolling forward to a newer shared framework. See https://github.com/dotnet/core-setup/pull/3704 - // Reading these versions could impact build perf, so we avoid doing it if we aren't publishing or if we are - // publishing a self-contained app. - bool includeRuntimeFileVersions = IsPublish && !IsSelfContained; - - DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext, includeRuntimeFileVersions) + DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext, IncludeRuntimeFileVersions) .WithMainProjectInDepsFile(IncludeMainProject) .WithReferenceAssemblies(referenceAssemblyInfos) .WithDirectReferences(directReferences) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets index dc7579271e06..0ae0fb07ba04 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets @@ -511,6 +511,13 @@ Copyright (c) .NET Foundation. All rights reserved. $(PublishDir)$(ProjectDepsFileName) + + true + IncludeRuntimeFileVersions="$(IncludeRuntimeFileVersions)" /> diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 0a28d2cf517c..087b65e61b80 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -142,7 +142,8 @@ Copyright (c) .NET Foundation. All rights reserved. PlatformLibraryName="$(MicrosoftNETPlatformLibrary)" FilesToSkip="@(_ConflictPackageFiles)" CompilerOptions="@(DependencyFileCompilerOptions)" - IsSelfContained="$(SelfContained)"> + IsSelfContained="$(SelfContained)" + IncludeRuntimeFileVersions="$(IncludeRuntimeFileVersions)"> From 30e87c6b10541af5fb27444dd3b4954a6979b620 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Mon, 9 Apr 2018 12:38:54 -0700 Subject: [PATCH 6/9] Add more end-to-end tests --- ...DepsJsonShouldContainVersionInformation.cs | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs index b3407498bb93..cc4da680185e 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs @@ -11,6 +11,7 @@ using Microsoft.NET.TestFramework.Assertions; using Microsoft.NET.TestFramework.Commands; using Microsoft.NET.TestFramework.ProjectConstruction; +using Newtonsoft.Json.Linq; using Xunit; using Xunit.Abstractions; @@ -134,8 +135,45 @@ private void Versions_are_not_included(bool build, [CallerMemberName] string cal } } - [Fact] + [Fact(Skip = "Host deps.json doesn't have runtime file version info yet: https://github.com/dotnet/sdk/issues/2124")] public void Inbox_version_of_assembly_is_loaded_over_applocal_version() + { + var (coreDir, publishDir, immutableDir) = TestConflictResult(); + immutableDir.Should().BeEquivalentTo(coreDir, "immutable collections library from Framework should win"); + } + + [Fact] + public void Inbox_version_is_loaded_if_runtime_file_versions_arent_in_deps() + { + void testProjectChanges(TestProject testProject) + { + testProject.AdditionalProperties["IncludeRuntimeFileVersions"] = "false"; + } + + var (coreDir, publishDir, immutableDir) = TestConflictResult(testProjectChanges); + immutableDir.Should().BeEquivalentTo(publishDir, "published immutable collections library from should win"); + } + + [Fact] + public void Local_version_of_assembly_with_higher_version_is_loaded_over_inbox_version() + { + void publishFolderChanges(string publishFolder) + { + var depsJsonPath = Path.Combine(publishFolder, "DepsJsonVersions.deps.json"); + var depsJson = JObject.Parse(File.ReadAllText(depsJsonPath)); + var target = ((JProperty)depsJson["targets"].First).Value; + var file = target["System.Collections.Immutable/1.5.0-preview1-26216-02"]["runtime"]["lib/netstandard2.0/System.Collections.Immutable.dll"]; + // Set fileVersion in deps.json to 4.7.0.0, which should be bigger than in box 4.6.x version + file["fileVersion"] = "4.7.0.0"; + File.WriteAllText(depsJsonPath, depsJson.ToString()); + } + + var (coreDir, publishDir, immutableDir) = TestConflictResult(publishFolderChanges: publishFolderChanges); + immutableDir.Should().BeEquivalentTo(publishDir, "published immutable collections library from should win"); + } + + private (string coreDir, string publishDir, string immutableDir) TestConflictResult( + Action testProjectChanges = null, Action publishFolderChanges = null) { var testProject = GetTestProject(); @@ -151,6 +189,11 @@ public static void Main() } } "; + if (testProjectChanges != null) + { + testProjectChanges(testProject); + } + var testAsset = _testAssetsManager.CreateTestProject(testProject) .Restore(Log, testProject.Name); @@ -163,6 +206,10 @@ public static void Main() var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier); + if (publishFolderChanges != null) + { + publishFolderChanges(publishDirectory.FullName); + } // Assembly from package should be deployed, as it is newer than the in-box version for netcoreapp2.0, // which is what the app targets @@ -195,7 +242,7 @@ public static void Main() string coreDir = Path.GetDirectoryName(stdOutLines[0]); string immutableDir = Path.GetDirectoryName(stdOutLines[1]); - immutableDir.Should().BeEquivalentTo(coreDir, "immutable collections library from Framework should win"); + return (coreDir, publishDirectory.FullName, immutableDir); } From adfc2bb0548fd2d7bf7b34079e888df22809e23f Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Tue, 17 Apr 2018 18:28:15 -0700 Subject: [PATCH 7/9] Style updates based on PR feedback --- .../GivenADependencyContextBuilder.cs | 4 ++-- ...tAPublishedDepsJsonShouldContainVersionInformation.cs | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenADependencyContextBuilder.cs b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenADependencyContextBuilder.cs index 4669534ca929..36bb92c9ab05 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenADependencyContextBuilder.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenADependencyContextBuilder.cs @@ -53,7 +53,7 @@ public void ItBuildsDependencyContextsFromProjectLockFiles( Constants.DefaultPlatformLibrary, isSelfContained: !string.IsNullOrEmpty(runtime)); - DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext, false) + DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext, includeRuntimeFileVersions: false) .WithDirectReferences(directReferences) .WithCompilationOptions(compilationOptions) .Build(); @@ -260,7 +260,7 @@ private DependencyContext BuildDependencyContextWithReferenceAssemblies(bool use useCompilationOptions ? CreateCompilationOptions() : null; - DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext, false) + DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext, includeRuntimeFileVersions: false) .WithReferenceAssemblies(ReferenceInfo.CreateReferenceInfos(referencePaths)) .WithCompilationOptions(compilationOptions) .Build(); diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs index cc4da680185e..9f909cf7952c 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs @@ -1,4 +1,7 @@ -using System; +// 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.Collections.Generic; using System.IO; using System.Linq; @@ -83,13 +86,13 @@ public void Versions_are_included_in_deps_json() [Fact] public void Versions_are_not_included_for_self_contained_apps() { - Versions_are_not_included(false); + Versions_are_not_included(build: false); } [Fact] public void Versions_are_not_included_for_build() { - Versions_are_not_included(true); + Versions_are_not_included(build: true); } private void Versions_are_not_included(bool build, [CallerMemberName] string callingMethod = "") From 5f34610806d28f18f0eabee67c07253563033d13 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 20 Apr 2018 14:13:50 -0700 Subject: [PATCH 8/9] Include file versions in deps file by default when targeting .NET Core or .NET Standard --- .../targets/Microsoft.NET.Publish.targets | 9 +-------- .../targets/Microsoft.NET.Sdk.BeforeCommon.targets | 4 ++++ .../targets/Microsoft.NET.Sdk.targets | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets index 0ae0fb07ba04..903eaf707ddc 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets @@ -511,13 +511,6 @@ Copyright (c) .NET Foundation. All rights reserved. $(PublishDir)$(ProjectDepsFileName) - - true + IncludeRuntimeFileVersions="$(IncludeFileVersionsInDependencyFile)" /> diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index 711115cf929e..c42fa0bdcecb 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -56,6 +56,10 @@ Copyright (c) .NET Foundation. All rights reserved. true + + + true .dll diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 087b65e61b80..3033892825b7 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -143,7 +143,7 @@ Copyright (c) .NET Foundation. All rights reserved. FilesToSkip="@(_ConflictPackageFiles)" CompilerOptions="@(DependencyFileCompilerOptions)" IsSelfContained="$(SelfContained)" - IncludeRuntimeFileVersions="$(IncludeRuntimeFileVersions)"> + IncludeRuntimeFileVersions="$(IncludeFileVersionsInDependencyFile)"> From d29e8a5c43f7ab3e31d32d2acfd8d2aa874ff629 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 20 Apr 2018 14:47:43 -0700 Subject: [PATCH 9/9] Update tests to always expect file versions in deps.json --- ...DepsJsonShouldContainVersionInformation.cs | 36 ++++++++----------- .../Microsoft.NET.ToolPack.Tests.csproj | 4 +++ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs index 9f909cf7952c..c34bb257bea2 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs @@ -58,8 +58,14 @@ public void Versions_are_included_in_deps_json() var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier); publishDirectory.Should().HaveFile(testProject.Name + ".deps.json"); + var depsFilePath = Path.Combine(publishDirectory.FullName, $"{testProject.Name}.deps.json"); + CheckVersionsInDepsFile(depsFilePath); + } + + void CheckVersionsInDepsFile(string depsFilePath) + { DependencyContext dependencyContext; - using (var depsJsonFileStream = File.OpenRead(Path.Combine(publishDirectory.FullName, $"{testProject.Name}.deps.json"))) + using (var depsJsonFileStream = File.OpenRead(depsFilePath)) { dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream); } @@ -84,18 +90,18 @@ public void Versions_are_included_in_deps_json() } [Fact] - public void Versions_are_not_included_for_self_contained_apps() + public void Versions_are_included_for_self_contained_apps() { - Versions_are_not_included(build: false); + Versions_are_included(build: false); } [Fact] - public void Versions_are_not_included_for_build() + public void Versions_are_included_for_build() { - Versions_are_not_included(build: true); + Versions_are_included(build: true); } - private void Versions_are_not_included(bool build, [CallerMemberName] string callingMethod = "") + private void Versions_are_included(bool build, [CallerMemberName] string callingMethod = "") { var testProject = GetTestProject(); testProject.RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid(testProject.TargetFrameworks); @@ -120,22 +126,8 @@ private void Versions_are_not_included(bool build, [CallerMemberName] string cal var outputDirectory = command.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier); outputDirectory.Should().HaveFile(testProject.Name + ".deps.json"); - DependencyContext dependencyContext; - using (var depsJsonFileStream = File.OpenRead(Path.Combine(outputDirectory.FullName, $"{testProject.Name}.deps.json"))) - { - dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream); - } - - var allRuntimeFiles = dependencyContext.RuntimeLibraries.SelectMany(rl => rl.NativeLibraryGroups.Concat(rl.RuntimeAssemblyGroups)) - .SelectMany(rag => rag.RuntimeFiles); - - allRuntimeFiles.Should().NotBeEmpty(); - - foreach (var runtimeFile in allRuntimeFiles) - { - runtimeFile.AssemblyVersion.Should().BeNull(); - runtimeFile.FileVersion.Should().BeNull(); - } + var depsFilePath = Path.Combine(outputDirectory.FullName, $"{testProject.Name}.deps.json"); + CheckVersionsInDepsFile(depsFilePath); } [Fact(Skip = "Host deps.json doesn't have runtime file version info yet: https://github.com/dotnet/sdk/issues/2124")] diff --git a/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj b/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj index 632b9cf5971c..01cc7a9ad3ff 100644 --- a/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj +++ b/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj @@ -19,6 +19,10 @@ + + +