From 8b1b153651bc0296cd0fac93fbb5b9c4e7f15fac Mon Sep 17 00:00:00 2001 From: Daniel Plaisted <daplaist@microsoft.com> Date: Tue, 27 Mar 2018 20:26:00 -0700 Subject: [PATCH] Add latest patch versions to BundledVersions.props, and tests to make sure that they are up to date --- Microsoft.DotNet.Cli.sln | 1 - .../TestAppSimple/TestAppSimple.csproj | 2 - build/MSBuildExtensions.targets | 5 + .../GivenSelfContainedAppsRollForward.cs | 142 ++++++++++++++++++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 test/EndToEnd/GivenSelfContainedAppsRollForward.cs diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 855541357..4b341ed9a 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -33,7 +33,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{89905EC4 build\BundledTemplates.proj = build\BundledTemplates.proj build\BundledTemplates.props = build\BundledTemplates.props build\BundledTools.props = build\BundledTools.props - build\BundledVersions.targets = build\BundledVersions.targets build\Compile.targets = build\Compile.targets build\CrossGen.props = build\CrossGen.props build\DependencyVersions.props = build\DependencyVersions.props diff --git a/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj b/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj index f99d38872..9c5f2a885 100755 --- a/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj +++ b/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj @@ -4,7 +4,5 @@ <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <OutputType>Exe</OutputType> - <!-- Issue: https://github.com/dotnet/sdk/issues/1150 --> - <DisableImplicitAssetTargetFallback>true</DisableImplicitAssetTargetFallback> </PropertyGroup> </Project> \ No newline at end of file diff --git a/build/MSBuildExtensions.targets b/build/MSBuildExtensions.targets index 09324294e..ab3e7e557 100644 --- a/build/MSBuildExtensions.targets +++ b/build/MSBuildExtensions.targets @@ -143,6 +143,11 @@ Copyright (c) .NET Foundation. All rights reserved. <BundledNETCorePlatformsPackageVersion>$(_NETCorePlatformsPackageVersion)</BundledNETCorePlatformsPackageVersion> <NETCoreSdkVersion>$(SdkVersion)</NETCoreSdkVersion> <_NETCoreSdkIsPreview>$(_NETCoreSdkIsPreview)</_NETCoreSdkIsPreview> + + <!-- Latest patch versions for each minor version of .NET Core --> + <LatestPatchVersionForNetCore1_0 Condition="'$(LatestPatchVersionForNetCore1_0)' == ''">1.0.10</LatestPatchVersionForNetCore1_0> + <LatestPatchVersionForNetCore1_1 Condition="'$(LatestPatchVersionForNetCore1_1)' == ''">1.1.7</LatestPatchVersionForNetCore1_1> + <LatestPatchVersionForNetCore2_0 Condition="'$(LatestPatchVersionForNetCore2_0)' == ''">2.0.6</LatestPatchVersionForNetCore2_0> </PropertyGroup> </Project> ]]> diff --git a/test/EndToEnd/GivenSelfContainedAppsRollForward.cs b/test/EndToEnd/GivenSelfContainedAppsRollForward.cs new file mode 100644 index 000000000..4bc4464bf --- /dev/null +++ b/test/EndToEnd/GivenSelfContainedAppsRollForward.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Xml.Linq; +using FluentAssertions; +using Microsoft.DotNet.TestFramework; +using Microsoft.DotNet.Tools.Test.Utilities; +using NuGet.ProjectModel; +using NuGet.Versioning; +using Xunit; + +namespace EndToEnd +{ + public class GivenSelfContainedAppsRollForward : TestBase + { + + [Theory] + // MemberData is used instead of InlineData here so we can access it in another test to + // verify that we are covering the latest release of .NET Core + [MemberData(nameof(SupportedNetCoreAppVersions))] + public void ItRollsForwardToTheLatestVersion(string minorVersion) + { + var _testInstance = TestAssets.Get("TestAppSimple") + .CreateInstance(identifier: minorVersion) + .WithSourceFiles(); + + string projectDirectory = _testInstance.Root.FullName; + + string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj"); + + var project = XDocument.Load(projectPath); + var ns = project.Root.Name.Namespace; + + // Update TargetFramework to the right version of .NET Core + project.Root.Element(ns + "PropertyGroup") + .Element(ns + "TargetFramework") + .Value = "netcoreapp" + minorVersion; + + var rid = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.GetRuntimeIdentifier(); + + // Set RuntimeIdentifier to opt in to roll-forward behavior + project.Root.Element(ns + "PropertyGroup") + .Add(new XElement(ns + "RuntimeIdentifier", rid)); + + project.Save(projectPath); + + // Get the version rolled forward to + new RestoreCommand() + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should().Pass(); + + string assetsFilePath = Path.Combine(projectDirectory, "obj", "project.assets.json"); + var assetsFile = new LockFileFormat().Read(assetsFilePath); + + var rolledForwardVersion = GetNetCoreAppVersion(assetsFile); + rolledForwardVersion.Should().NotBeNull(); + + if (rolledForwardVersion.IsPrerelease) + { + // If this version of .NET Core is still prerelease, then: + // - Floating the patch by adding ".*" to the major.minor version won't work, but + // - There aren't any patches to roll-forward to, so we skip testing this until the version + // leaves prerelease. + return; + } + + // Float the RuntimeFrameworkVersion to get the latest version of the runtime available from feeds + Directory.Delete(Path.Combine(projectDirectory, "obj"), true); + project.Root.Element(ns + "PropertyGroup") + .Add(new XElement(ns + "RuntimeFrameworkVersion", $"{minorVersion}.*")); + project.Save(projectPath); + + new RestoreCommand() + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should().Pass(); + + var floatedAssetsFile = new LockFileFormat().Read(assetsFilePath); + + var floatedVersion = GetNetCoreAppVersion(floatedAssetsFile); + floatedVersion.Should().NotBeNull(); + + rolledForwardVersion.ToNormalizedString().Should().BeEquivalentTo(floatedVersion.ToNormalizedString(), + "the latest patch version properties in Microsoft.NETCoreSdk.BundledVersions.props need to be updated " + + "(see MSBuildExtensions.targets in this repo)"); + } + + private NuGetVersion GetNetCoreAppVersion(LockFile lockFile) + { + return lockFile?.Targets?.SingleOrDefault(t => t.RuntimeIdentifier != null) + ?.Libraries?.SingleOrDefault(l => + string.Compare(l.Name, "Microsoft.NETCore.App", StringComparison.CurrentCultureIgnoreCase) == 0) + ?.Version; + } + + [Fact] + public void WeCoverLatestNetCoreAppRollForward() + { + // Run "dotnet new console", get TargetFramework property, and make sure it's covered in SupportedNetCoreAppVersions + using (DisposableDirectory directory = Temp.CreateDirectory()) + { + string projectDirectory = directory.Path; + + new NewCommandShim() + .WithWorkingDirectory(projectDirectory) + .Execute("console --no-restore") + .Should().Pass(); + + string projectPath = Path.Combine(projectDirectory, Path.GetFileName(projectDirectory) + ".csproj"); + + var project = XDocument.Load(projectPath); + var ns = project.Root.Name.Namespace; + + string targetFramework = project.Root.Element(ns + "PropertyGroup") + .Element(ns + "TargetFramework") + .Value; + + SupportedNetCoreAppVersions.Select(v => $"netcoreapp{v[0]}") + .Should().Contain(targetFramework, $"the {nameof(SupportedNetCoreAppVersions)} property should include the default version " + + "of .NET Core created by \"dotnet new\""); + + } + } + + public static IEnumerable<object[]> SupportedNetCoreAppVersions + { + get + { + return new[] + { + "1.0", + "1.1", + "2.0", + "2.1" + }.Select(version => new object[] { version }); + } + } + } +}