Fix dotnet new classlib to contain the correct NETStandard.Library version.

Fix #5638
This commit is contained in:
Eric Erhardt 2017-02-10 14:14:04 -06:00
parent 68ad8bdec6
commit 25f9a1bbc7
5 changed files with 68 additions and 12 deletions

View file

@ -24,14 +24,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestPackages", "TestPackage
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{89905EC4-BC0F-443B-8ADF-691321F10108}"
ProjectSection(SolutionItems) = preProject
build\Microsoft.DotNet.Cli.BundledSdks.proj = build\Microsoft.DotNet.Cli.BundledSdks.proj
build\Microsoft.DotNet.Cli.BundledSdks.props = build\Microsoft.DotNet.Cli.BundledSdks.props
build\Microsoft.DotNet.Cli.BundledTemplates.proj = build\Microsoft.DotNet.Cli.BundledTemplates.proj
build\Microsoft.DotNet.Cli.BundledTemplates.props = build\Microsoft.DotNet.Cli.BundledTemplates.props
build\Microsoft.DotNet.Cli.Compile.targets = build\Microsoft.DotNet.Cli.Compile.targets
build\Microsoft.DotNet.Cli.DependencyVersions.props = build\Microsoft.DotNet.Cli.DependencyVersions.props
build\Microsoft.DotNet.Cli.GitCommitInfo.targets = build\Microsoft.DotNet.Cli.GitCommitInfo.targets
build\Microsoft.DotNet.Cli.HostInfo.targets = build\Microsoft.DotNet.Cli.HostInfo.targets
build\Microsoft.DotNet.Cli.InitRepo.props = build\Microsoft.DotNet.Cli.InitRepo.props
build\Microsoft.DotNet.Cli.InitRepo.targets = build\Microsoft.DotNet.Cli.InitRepo.targets
build\Microsoft.DotNet.Cli.Monikers.props = build\Microsoft.DotNet.Cli.Monikers.props
build\Microsoft.DotNet.Cli.Package.targets = build\Microsoft.DotNet.Cli.Package.targets
build\Microsoft.DotNet.Cli.Prepare.targets = build\Microsoft.DotNet.Cli.Prepare.targets
build\Microsoft.DotNet.Cli.Publish.targets = build\Microsoft.DotNet.Cli.Publish.targets
build\Microsoft.DotNet.Cli.Run.targets = build\Microsoft.DotNet.Cli.Run.targets
build\Microsoft.DotNet.Cli.Signing.proj = build\Microsoft.DotNet.Cli.Signing.proj
build\Microsoft.DotNet.Cli.tasks = build\Microsoft.DotNet.Cli.tasks
build\Microsoft.DotNet.Cli.Test.targets = build\Microsoft.DotNet.Cli.Test.targets
EndProjectSection

View file

@ -11,6 +11,6 @@
<CLI_TestPlatform_Version>15.0.0-preview-20170125-04</CLI_TestPlatform_Version>
<TemplateEngineVersion>1.0.0-beta1-20170202-111</TemplateEngineVersion>
<TemplateEngineTemplateVersion>1.0.0-beta1-20170131-110</TemplateEngineTemplateVersion>
<TemplateEngineTemplate2_0Version>1.0.0-beta1-20170207-114</TemplateEngineTemplate2_0Version>
<TemplateEngineTemplate2_0Version>1.0.0-beta1-20170209-117</TemplateEngineTemplate2_0Version>
</PropertyGroup>
</Project>

View file

@ -1,6 +1,7 @@
// 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.IO;
using System.Linq;
using Microsoft.DotNet.PlatformAbstractions;
@ -16,10 +17,14 @@ namespace Microsoft.DotNet.Cli.Utils
internal class FrameworkDependencyFile
{
private readonly string _depsFilePath;
private readonly Lazy<DependencyContext> _dependencyContext;
private DependencyContext DependencyContext => _dependencyContext.Value;
public FrameworkDependencyFile()
{
_depsFilePath = Muxer.GetDataFromAppDomain("FX_DEPS_FILE");
_dependencyContext = new Lazy<DependencyContext>(CreateDependencyContext);
}
public bool SupportsCurrentRuntime()
@ -29,9 +34,15 @@ namespace Microsoft.DotNet.Cli.Utils
public bool IsRuntimeSupported(string runtimeIdentifier)
{
DependencyContext fxDependencyContext = CreateDependencyContext();
return DependencyContext.RuntimeGraph.Any(g => g.Runtime == runtimeIdentifier);
}
return fxDependencyContext.RuntimeGraph.Any(g => g.Runtime == runtimeIdentifier);
public string GetNetStandardLibraryVersion()
{
return DependencyContext
.RuntimeLibraries
.FirstOrDefault(l => "netstandard.library".Equals(l.Name, StringComparison.OrdinalIgnoreCase))
?.Version;
}
private DependencyContext CreateDependencyContext()

View file

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Cli;
@ -54,6 +53,7 @@ namespace Microsoft.DotNet.Tools.New
{ "prefs:language", "C#" },
{ "dotnet-cli-version", Product.Version },
{ "RuntimeFrameworkVersion", new Muxer().SharedFxVersion },
{ "NetStandardImplicitPackageVersion", new FrameworkDependencyFile().GetNetStandardLibraryVersion() },
};
return new DefaultTemplateEngineHost(HostIdentifier, "v" + Product.Version, CultureInfo.CurrentCulture.Name, preferences, builtIns);

View file

@ -1,10 +1,12 @@
// 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 Microsoft.DotNet.Tools.Test.Utilities;
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.New.Tests
@ -16,13 +18,15 @@ namespace Microsoft.DotNet.New.Tests
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute($"new console --debug:ephemeral-hive");
new NewCommand()
.WithWorkingDirectory(rootPath)
.Execute($"console --debug:ephemeral-hive");
DateTime expectedState = Directory.GetLastWriteTime(rootPath);
var result = new TestCommand("dotnet") { WorkingDirectory = rootPath }
.ExecuteWithCapturedOutput($"new console --debug:ephemeral-hive");
var result = new NewCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput($"console --debug:ephemeral-hive");
DateTime actualState = Directory.GetLastWriteTime(rootPath);
@ -55,14 +59,47 @@ namespace Microsoft.DotNet.New.Tests
string projectFolder,
string packagesDirectory)
{
new TestCommand("dotnet") { WorkingDirectory = projectFolder }
.Execute($"new {projectType} --debug:ephemeral-hive")
new NewCommand()
.WithWorkingDirectory(projectFolder)
.Execute($"{projectType} --debug:ephemeral-hive")
.Should().Pass();
new RestoreCommand()
.WithWorkingDirectory(projectFolder)
.Execute($"--packages {packagesDirectory} /p:SkipInvalidConfigurations=true")
.Execute($"--packages {packagesDirectory}")
.Should().Pass();
}
[Fact]
public void NewClassLibRestoresCorrectNetStandardLibraryVersion()
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
var packagesDirectory = Path.Combine(rootPath, "packages");
var projectName = "Library";
var projectFileName = $"{projectName}.csproj";
new NewCommand()
.WithWorkingDirectory(rootPath)
.Execute($"classlib --name {projectName} -o .")
.Should().Pass();
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"))
.Should().Exist()
.And.HaveDirectory(expectedVersion);
}
}
}