internal void ItDoesNotRollForwardToTheLatestVersion(string packageName, string minorVersion)
        {
            var testProjectCreator = new TestProjectCreator()
            {
                PackageName  = packageName,
                MinorVersion = minorVersion,
            };

            var _testInstance = testProjectCreator.Create();

            string projectDirectory = _testInstance.Root.FullName;

            string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");

            //  Get the resolved version of .NET Core
            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            string assetsFilePath = Path.Combine(projectDirectory, "obj", "project.assets.json");
            var    assetsFile     = new LockFileFormat().Read(assetsFilePath);

            var versionInAssertsJson = GetPackageVersion(assetsFile, packageName);

            versionInAssertsJson.Should().NotBeNull();

            if (versionInAssertsJson.IsPrerelease && versionInAssertsJson.Patch == 0)
            {
                // if the bundled version is, for example, a prerelease of
                // .NET Core 2.1.1, that we don't roll forward to that prerelease
                // version for framework-dependent deployments.
                return;
            }

            versionInAssertsJson.ToNormalizedString().Should().BeEquivalentTo(GetExpectedVersion(packageName, minorVersion));
        }
        internal void ItRollsForwardToTheLatestVersion(string packageName, string minorVersion)
        {
            var testProjectCreator = new TestProjectCreator()
            {
                PackageName  = packageName,
                MinorVersion = minorVersion,
                //  Set RuntimeIdentifier to opt in to roll-forward behavior
                RuntimeIdentifier = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.GetRuntimeIdentifier()
            };

            var testInstance = testProjectCreator.Create();

            string projectDirectory = testInstance.Root.FullName;

            //  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 = GetPackageVersion(assetsFile, packageName);

            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;
            }

            testProjectCreator.Identifier = "floating";

            var floatingProjectInstance = testProjectCreator.Create();

            var floatingProjectPath = Path.Combine(floatingProjectInstance.Root.FullName, "TestAppSimple.csproj");

            var floatingProject = XDocument.Load(floatingProjectPath);
            var ns = floatingProject.Root.Name.Namespace;


            if (packageName == TestProjectCreator.NETCorePackageName)
            {
                //  Float the RuntimeFrameworkVersion to get the latest version of the runtime available from feeds
                floatingProject.Root.Element(ns + "PropertyGroup")
                .Add(new XElement(ns + "RuntimeFrameworkVersion", $"{minorVersion}.*"));
            }
            else
            {
                floatingProject.Root.Element(ns + "ItemGroup")
                .Element(ns + "PackageReference")
                .Add(new XAttribute("Version", $"{minorVersion}.*"),
                     new XAttribute("AllowExplicitVersion", "true"));
            }

            floatingProject.Save(floatingProjectPath);

            new RestoreCommand()
            .WithWorkingDirectory(floatingProjectInstance.Root.FullName)
            .Execute()
            .Should().Pass();

            string floatingAssetsFilePath = Path.Combine(floatingProjectInstance.Root.FullName, "obj", "project.assets.json");

            var floatedAssetsFile = new LockFileFormat().Read(floatingAssetsFilePath);

            var floatedVersion = GetPackageVersion(floatedAssetsFile, packageName);

            floatedVersion.Should().NotBeNull();

            rolledForwardVersion.ToNormalizedString().Should().BeEquivalentTo(floatedVersion.ToNormalizedString(),
                                                                              $"the latest patch version for {packageName} {minorVersion} in Microsoft.NETCoreSdk.BundledVersions.props " +
                                                                              "needs to be updated (see the ImplicitPackageVariable items in MSBuildExtensions.targets in this repo)");
        }
        public void DefaultRuntimeVersionsAreUpToDate()
        {
            var outputFile         = "resolvedVersions.txt";
            var testProjectCreator = new TestProjectCreator()
            {
                PackageName  = "DefaultRuntimeVersionsAreUpToDate",
                MinorVersion = "3.0"
            };
            var testProject = testProjectCreator.Create();

            var    projectFile = new DirectoryInfo(testProject.Root.FullName).GetFiles("*.csproj").First().FullName;
            var    project     = XDocument.Load(projectFile);
            string writeResolvedVersionsTarget = @$ "
    <Target Name=`WriteResolvedVersions` AfterTargets=`PrepareForBuild;ProcessFrameworkReferences`>
        <ItemGroup>
            <LinesToWrite Include=`%(KnownFrameworkReference.Identity) %(KnownFrameworkReference.DefaultRuntimeFrameworkVersion) %(KnownFrameworkReference.LatestRuntimeFrameworkVersion)`/>
        </ItemGroup>
        <WriteLinesToFile File=`$(OutputPath){ outputFile }`
                          Lines=`@(LinesToWrite)`
                          Overwrite=`true`
                          Encoding=`Unicode`/>

      </Target>";

            writeResolvedVersionsTarget = writeResolvedVersionsTarget.Replace('`', '"');
            var targetElement = XElement.Parse(writeResolvedVersionsTarget);
            var ns            = project.Root.Name.Namespace;

            foreach (var elem in targetElement.Descendants())
            {
                elem.Name = ns + elem.Name.LocalName;
            }
            targetElement.Name = ns + targetElement.Name.LocalName;
            project.Root.Add(targetElement);
            using (var file = File.CreateText(projectFile))
            {
                project.Save(file);
            }

            new RestoreCommand()
            .WithWorkingDirectory(testProject.Root.FullName)
            .Execute()
            .Should().Pass();

            var binDirectory = new DirectoryInfo(testProject.Root.FullName).Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault();

            binDirectory.Should().HaveFilesMatching(outputFile, SearchOption.TopDirectoryOnly);
            var resolvedVersionsFile = File.ReadAllLines(Path.Combine(binDirectory.FullName, outputFile));

            foreach (var framework in frameworks)
            {
                foreach (var version in versions)
                {
                    var frameworkVersionLine = resolvedVersionsFile.Where(line => line.Contains(framework) && line.Contains(version)).FirstOrDefault();
                    frameworkVersionLine.Should().NotBeNullOrEmpty();
                    var defaultVersion = NuGetVersion.Parse(frameworkVersionLine.Split(" ")[1]);
                    var latestVersion  = NuGetVersion.Parse(frameworkVersionLine.Split(" ")[2]);

                    if (latestVersion.Patch == 0 && latestVersion.IsPrerelease)
                    {
                        defaultVersion.Should().Be(latestVersion,
                                                   $"the DefaultRuntimeFrameworkVersion for { framework } { version } in Microsoft.NETCoreSdk.BundledVersions.props does not match latest prerelease version { latestVersion }");
                    }
                    else
                    {
                        defaultVersion.Should().Be(new NuGetVersion(latestVersion.Major, latestVersion.Minor, 0),
                                                   $"the DefaultRuntimeFrameworkVersion for { framework } { version } in Microsoft.NETCoreSdk.BundledVersions.props needs to be updated to { version }.0");
                    }
                }
            }
        }
Example #4
0
        public void ItRollsForwardToTheLatestVersion(string minorVersion)
        {
            if (minorVersion == "3.0")
            {
                //  https://github.com/dotnet/core-sdk/issues/621
                return;
            }

            var testProjectCreator = new TestProjectCreator(identifier: minorVersion)
            {
                PackageName  = TestProjectCreator.AspNetCoreAppPackageName,
                MinorVersion = minorVersion,
            };

            var _testInstance = testProjectCreator.Create()
                                .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 = GetAspNetCoreAppVersion(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 = GetAspNetCoreAppVersion(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)");
        }