diff --git a/build/BundledVersions.targets b/build/BundledVersions.targets new file mode 100644 index 000000000..065eefe96 --- /dev/null +++ b/build/BundledVersions.targets @@ -0,0 +1,67 @@ + + + $(IntermediateDirectory)/GeneratedMSBuildImports + 15.0/Imports/Microsoft.Common.props/ImportBefore + Microsoft.NETCoreSdk.BundledVersions.props + + + + + + + <_NETStandardLibraryVersions Include="@(PackageDefinitions->'%(Version)')" + Condition="%(PackageDefinitions.Name) == 'NetStandard.Library'" /> + + + + + + <_NETCoreAppPackageVersion>$(CLI_SharedFrameworkVersion) + <_NETStandardPackageVersion>@(_NETStandardLibraryVersions->Distinct()) + + + <_NETCoreAppTargetFrameworkVersion>$(_NETCoreAppPackageVersion.Split('.')[0]).$(_NETCoreAppPackageVersion.Split('.')[1]) + <_NETStandardTargetFrameworkVersion>$(_NETStandardPackageVersion.Split('.')[0]).$(_NETStandardPackageVersion.Split('.')[1]) + + + + + + $(_NETCoreAppTargetFrameworkVersion) + $(_NETCoreAppPackageVersion) + $(_NETStandardTargetFrameworkVersion) + $(_NETStandardPackageVersion) + + +]]> + + + + + + + + + + + + diff --git a/run-build.ps1 b/run-build.ps1 index c02a924cf..ea77e8983 100644 --- a/run-build.ps1 +++ b/run-build.ps1 @@ -101,8 +101,8 @@ if ($LastExitCode -ne 0) # install the post-PJnistic stage0 $dotnetInstallPath = Join-Path $toolsLocalPath "dotnet-install.ps1" -Write-Host "$dotnetInstallPath -Channel ""master"" -Version ""2.0.0-preview1-005390"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" -Invoke-Expression "$dotnetInstallPath -Channel ""master"" -Version ""2.0.0-preview1-005390"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" +Write-Host "$dotnetInstallPath -Channel ""master"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" +Invoke-Expression "$dotnetInstallPath -Channel ""master"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" if ($LastExitCode -ne 0) { Write-Output "The .NET CLI installation failed with exit code $LastExitCode" diff --git a/run-build.sh b/run-build.sh index 684fb8049..17c515902 100755 --- a/run-build.sh +++ b/run-build.sh @@ -167,8 +167,8 @@ if [ $? != 0 ]; then fi # now execute the script -echo "installing CLI: $dotnetInstallPath --channel \"master\" --version \"2.0.0-preview1-005165\" --install-dir $DOTNET_INSTALL_DIR --architecture \"$ARCHITECTURE\" $LINUX_PORTABLE_INSTALL_ARGS" -$dotnetInstallPath --channel "master" --version "2.0.0-preview1-005390" --install-dir $DOTNET_INSTALL_DIR --architecture "$ARCHITECTURE" $LINUX_PORTABLE_INSTALL_ARGS +echo "installing CLI: $dotnetInstallPath --channel \"master\" --install-dir $DOTNET_INSTALL_DIR --architecture \"$ARCHITECTURE\" $LINUX_PORTABLE_INSTALL_ARGS" +$dotnetInstallPath --channel "master" --install-dir $DOTNET_INSTALL_DIR --architecture "$ARCHITECTURE" $LINUX_PORTABLE_INSTALL_ARGS if [ $? != 0 ]; then echo "run-build: Error: Boot-strapping post-PJ stage0 with exit code $?." >&2 exit $? diff --git a/src/redist/redist.csproj b/src/redist/redist.csproj index 7c7ef6569..5bf539615 100644 --- a/src/redist/redist.csproj +++ b/src/redist/redist.csproj @@ -2,6 +2,7 @@ + $(CliVersionPrefix) diff --git a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs index 649fa62ff..ac0610240 100644 --- a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs +++ b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Xml.Linq; using FluentAssertions; using Microsoft.DotNet.Tools.Test.Utilities; +using Microsoft.Extensions.DependencyModel; using Xunit; namespace Microsoft.DotNet.New.Tests @@ -70,36 +71,87 @@ namespace Microsoft.DotNet.New.Tests .Should().Pass(); } - [Fact] - public void NewClassLibRestoresCorrectNetStandardLibraryVersion() + [Theory] + [InlineData("console", "RuntimeFrameworkVersion", "microsoft.netcore.app")] + [InlineData("classlib", "NetStandardImplicitPackageVersion", "netstandard.library")] + public void NewProjectRestoresCorrectPackageVersion(string type, string propertyName, string packageName) { - var rootPath = TestAssets.CreateTestDirectory().FullName; + // These will fail when templates stop including explicit version. + // Collapse back to one method and remove the explicit version handling when that happens. + NewProjectRestoresCorrectPackageVersion(type, propertyName, packageName, deleteExplicitVersion: true); + NewProjectRestoresCorrectPackageVersion(type, propertyName, packageName, deleteExplicitVersion: false); + } + + private void NewProjectRestoresCorrectPackageVersion(string type, string propertyName, string packageName, bool deleteExplicitVersion) + { + var rootPath = TestAssets.CreateTestDirectory(identifier: $"_{type}_{deleteExplicitVersion}").FullName; var packagesDirectory = Path.Combine(rootPath, "packages"); - var projectName = "Library"; - var projectFileName = $"{projectName}.csproj"; + var projectName = "Project"; + var expectedVersion = GetFrameworkPackageVersion(); new NewCommand() .WithWorkingDirectory(rootPath) - .Execute($"classlib --name {projectName} -o .") + .Execute($"{type} --name {projectName} -o .") .Should().Pass(); + ValidateAndRemoveExplicitVersion(); + new RestoreCommand() .WithWorkingDirectory(rootPath) .Execute($"--packages {packagesDirectory}") .Should().Pass(); - var expectedVersion = XDocument.Load(Path.Combine(rootPath, projectFileName)) - .Elements("Project") - .Elements("PropertyGroup") - .Elements("NetStandardImplicitPackageVersion") - .FirstOrDefault() - ?.Value; - - expectedVersion.Should().NotBeNullOrEmpty("Could not find NetStandardImplicitPackageVersion property in a new classlib."); - - new DirectoryInfo(Path.Combine(packagesDirectory, "netstandard.library")) + new DirectoryInfo(Path.Combine(packagesDirectory, packageName)) .Should().Exist() .And.HaveDirectory(expectedVersion); + + string GetFrameworkPackageVersion() + { + var dotnetDir = new FileInfo(DotnetUnderTest.FullName).Directory; + var sharedFxDir = dotnetDir + .GetDirectory("shared", "Microsoft.NETCore.App") + .EnumerateDirectories() + .Single(d => d.Name.StartsWith("2.0.0")); + + if (packageName == "microsoft.netcore.app") + { + return sharedFxDir.Name; + } + + var depsFile = Path.Combine(sharedFxDir.FullName, "Microsoft.NETCore.App.deps.json"); + using (var stream = File.OpenRead(depsFile)) + using (var reader = new DependencyContextJsonReader()) + { + var context = reader.Read(stream); + var dependency = context + .RuntimeLibraries + .Single(library => library.Name == packageName); + + return dependency.Version; + } + } + + // Remove when templates stop putting an explicit version + void ValidateAndRemoveExplicitVersion() + { + var projectFileName = $"{projectName}.csproj"; + var projectPath = Path.Combine(rootPath, projectFileName); + var projectDocument = XDocument.Load(projectPath); + var explicitVersionNode = projectDocument + .Elements("Project") + .Elements("PropertyGroup") + .Elements(propertyName) + .SingleOrDefault(); + + explicitVersionNode.Should().NotBeNull(); + explicitVersionNode.Value.Should().Be(expectedVersion); + + if (deleteExplicitVersion) + { + explicitVersionNode.Remove(); + projectDocument.Save(projectPath); + } + } } } }