From d6cab4af58ca885690a1d16bd0aa54bbddc92875 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Sun, 4 Dec 2016 22:31:58 -0800 Subject: [PATCH] use Sdks attribute in `dotnet new` templates (#4916) * Move dotnet-new templates to Sdk attribute * Update to MSBuild 15.1.0-preview-000454-01 To pick up a fix for Microsoft/msbuild#1431. * Fix template newlines * Fix casing on Microsoft.Net.Sdk * Move migration test csproj's to Sdk attribute * Disable parallel sdk restore Each SDK restore operation will try to manipulate the same assets.json file since the dependency name&version are injected into a common csproj file. This can cause runtime failures when two NuGets try to restore the project at once. * Make casing of SDK 'NET' and not 'Net' * Remove redundatn imports * Fix test string * Additional race * Replacing the SDK with the Web.Sdk when it is a Web project. * Fixing the test by writting the csproj before running the migration rule. --- .../MSBuildIntegration/build.props | 2 +- .../CsprojLibrary1/CsprojLibrary1.csproj | 9 +-- .../CsprojLibrary2/CsprojLibrary2.csproj | 9 +-- .../CsprojLibrary3/CsprojLibrary3.csproj | 9 +-- build/Microsoft.DotNet.Cli.BundledSdks.proj | 3 + build/Microsoft.DotNet.Cli.BundledSdks.props | 2 +- build/Microsoft.DotNet.Cli.Compile.targets | 4 +- ...rosoft.DotNet.Cli.DependencyVersions.props | 2 +- .../ConstantPackageVersions.cs | 1 + .../MigrationSettings.cs | 9 +-- .../ProjectMigrator.cs | 1 - .../MigratePackageDependenciesAndToolsRule.cs | 22 ------- .../Rules/MigrateWebSdkRule.cs | 40 ++++++++++++ .../commands/dotnet-migrate/MigrateCommand.cs | 5 -- .../dotnet-msbuild/MSBuildForwardingApp.cs | 4 +- .../CSharp_Console/$projectName$.csproj | 16 ++--- .../CSharp_Lib/$projectName$.csproj | 12 +--- .../CSharp_Mstest/$projectName$.csproj | 26 ++------ .../CSharp_Xunittest/$projectName$.csproj | 26 ++------ .../GivenAProjectMigrator.cs | 6 +- .../ProjectJsonBuilder.cs | 1 - .../GivenThatIWantToMigrateAssemblyInfo.cs | 2 +- .../GivenThatIWantToMigrateBuildOptions.cs | 2 +- ...enThatIWantToMigratePackageDependencies.cs | 31 +-------- ...enThatIWantToMigrateProjectDependencies.cs | 12 ++-- .../GivenThatIWantToMigrateRuntimeOptions.cs | 4 +- .../Rules/GivenThatIWantToMigrateTFMs.cs | 8 +-- .../GivenThatIWantToMigrateWebProjects.cs | 64 +++++++++++++++++++ .../TemporaryProjectFileRuleRunner.cs | 2 +- .../Commands/TestCommand.cs | 22 ++++++- 30 files changed, 179 insertions(+), 177 deletions(-) create mode 100644 src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateWebSdkRule.cs create mode 100644 test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateWebProjects.cs diff --git a/TestAssets/TestProjects/MSBuildIntegration/build.props b/TestAssets/TestProjects/MSBuildIntegration/build.props index f667330b5..3d640d339 100644 --- a/TestAssets/TestProjects/MSBuildIntegration/build.props +++ b/TestAssets/TestProjects/MSBuildIntegration/build.props @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj index 15bfca704..06471fc11 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj @@ -1,5 +1,4 @@ - - + @@ -14,14 +13,8 @@ - - $(CLI_NETSDK_Version) - All - 1.6.0 - - diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj index 15bfca704..06471fc11 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj @@ -1,5 +1,4 @@ - - + @@ -14,14 +13,8 @@ - - $(CLI_NETSDK_Version) - All - 1.6.0 - - diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj index 15bfca704..06471fc11 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj @@ -1,5 +1,4 @@ - - + @@ -14,14 +13,8 @@ - - $(CLI_NETSDK_Version) - All - 1.6.0 - - diff --git a/build/Microsoft.DotNet.Cli.BundledSdks.proj b/build/Microsoft.DotNet.Cli.BundledSdks.proj index 83ba01541..4408ca0a4 100644 --- a/build/Microsoft.DotNet.Cli.BundledSdks.proj +++ b/build/Microsoft.DotNet.Cli.BundledSdks.proj @@ -16,6 +16,9 @@ Outputs="@(SdkContent->'$(SdkLayoutDirectory)/%(RecursiveDir)%(FileName)%(Extension)')"> + + diff --git a/build/Microsoft.DotNet.Cli.BundledSdks.props b/build/Microsoft.DotNet.Cli.BundledSdks.props index 3045f6462..0babb29ae 100644 --- a/build/Microsoft.DotNet.Cli.BundledSdks.props +++ b/build/Microsoft.DotNet.Cli.BundledSdks.props @@ -4,7 +4,7 @@ - + diff --git a/build/Microsoft.DotNet.Cli.Compile.targets b/build/Microsoft.DotNet.Cli.Compile.targets index 019a79aed..bf8d939ce 100644 --- a/build/Microsoft.DotNet.Cli.Compile.targets +++ b/build/Microsoft.DotNet.Cli.Compile.targets @@ -251,7 +251,7 @@ CLIBuildDll=$(CLIBuildDll); NuGetPackagesDir=$(NuGetPackagesDir); - SdkLayoutDirectory=$(SdkOutputDirectory)/Extensions/%(BundledSdk.Identity); + SdkLayoutDirectory=$(SdkOutputDirectory)/Sdks/%(BundledSdk.Identity); SdkPackageName=%(BundledSdk.Identity); SdkPackageVersion=%(BundledSdk.Version); Stage0Directory=$(Stage0Directory) @@ -260,7 +260,7 @@ diff --git a/build/Microsoft.DotNet.Cli.DependencyVersions.props b/build/Microsoft.DotNet.Cli.DependencyVersions.props index 8d2c23ef1..9f7ef66ab 100644 --- a/build/Microsoft.DotNet.Cli.DependencyVersions.props +++ b/build/Microsoft.DotNet.Cli.DependencyVersions.props @@ -1,7 +1,7 @@ - 15.1.0-preview-000451-02 + 15.1.0-preview-000454-01 1.0.0-alpha-20161104-2 1.0.0-alpha-20161104-2-112 diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs index f1ccc0b88..12f891dde 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs @@ -12,5 +12,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration public const string MstestTestAdapterVersion = "1.1.3-preview"; public const string MstestTestFrameworkVersion = "1.0.4-preview"; public const string BundleMinifierToolVersion = "2.2.301"; + public const string WebSdkPackageVersion = "1.0.0-alpha-20161117-1-119" ; } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/MigrationSettings.cs b/src/Microsoft.DotNet.ProjectJsonMigration/MigrationSettings.cs index 714c4db4e..77014b747 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/MigrationSettings.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/MigrationSettings.cs @@ -13,18 +13,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration public string ProjectXProjFilePath { get; } public string ProjectDirectory { get; } public string OutputDirectory { get; } - public string SdkPackageVersion { get; } public ProjectRootElement MSBuildProjectTemplate { get; } public string SdkDefaultsFilePath { get; } public MigrationSettings( string projectDirectory, string outputDirectory, - string sdkPackageVersion, ProjectRootElement msBuildProjectTemplate, string projectXprojFilePath=null, string sdkDefaultsFilePath=null) : this( - projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath) + projectDirectory, outputDirectory, projectXprojFilePath, sdkDefaultsFilePath) { MSBuildProjectTemplate = msBuildProjectTemplate != null ? msBuildProjectTemplate.DeepClone() : null; } @@ -32,11 +30,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration public MigrationSettings( string projectDirectory, string outputDirectory, - string sdkPackageVersion, string msBuildProjectTemplatePath, string projectXprojFilePath=null, string sdkDefaultsFilePath=null) : this( - projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath) + projectDirectory, outputDirectory, projectXprojFilePath, sdkDefaultsFilePath) { _msBuildProjectTemplatePath = msBuildProjectTemplatePath; MSBuildProjectTemplate = ProjectRootElement.Open( @@ -48,13 +45,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration private MigrationSettings( string projectDirectory, string outputDirectory, - string sdkPackageVersion, string projectXprojFilePath=null, string sdkDefaultsFilePath=null) { ProjectDirectory = projectDirectory; OutputDirectory = outputDirectory; - SdkPackageVersion = sdkPackageVersion; ProjectXProjFilePath = projectXprojFilePath; SdkDefaultsFilePath = sdkDefaultsFilePath; } diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs index 6cb69ae68..a3ab045f9 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs @@ -74,7 +74,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration var projectDir = Path.GetDirectoryName(project.ProjectFilePath); var settings = new MigrationSettings(projectDir, projectDir, - rootSettings.SdkPackageVersion, tempMSBuildProjectTemplate); MigrateProject(settings); projectMigrationReports.Add(MigrateProject(settings)); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index 633ee3107..5e655fba0 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -39,16 +39,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules var noFrameworkPackageReferenceItemGroup = migrationRuleInputs.OutputMSBuildProject.AddItemGroup(); - // Inject Sdk dependency - _transformApplicator.Execute( - SdkPackageDependencyTransform.Transform( - new PackageDependencyInfo - { - Name = PackageConstants.SdkPackageName, - Version = migrationSettings.SdkPackageVersion, - PrivateAssets = "All" - }), noFrameworkPackageReferenceItemGroup, mergeExisting: false); - AddProjectTypeSpecificDependencies( migrationRuleInputs, migrationSettings, @@ -90,18 +80,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules var type = project.GetProjectType(); switch (type) { - case ProjectType.Web: - _transformApplicator.Execute( - SdkPackageDependencyTransform.Transform( - new PackageDependencyInfo - { - Name = PackageConstants.WebSdkPackageName, - Version = migrationSettings.SdkPackageVersion, - PrivateAssets = "All" - }), - noFrameworkPackageReferenceItemGroup, - mergeExisting: false); - break; case ProjectType.Test: _transformApplicator.Execute( PackageDependencyInfoTransform().Transform( diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateWebSdkRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateWebSdkRule.cs new file mode 100644 index 000000000..3a3fd5889 --- /dev/null +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateWebSdkRule.cs @@ -0,0 +1,40 @@ +// 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.IO; +using Microsoft.Build.Construction; + +namespace Microsoft.DotNet.ProjectJsonMigration.Rules +{ + //HACK to workaround https://github.com/Microsoft/msbuild/issues/1429 + internal class MigrateWebSdkRule : IMigrationRule + { + private static string GetContainingFolderName(string projectDirectory) + { + projectDirectory = projectDirectory.TrimEnd(new char[] { '/', '\\' }); + return Path.GetFileName(projectDirectory); + } + + public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs) + { + var project = migrationRuleInputs.DefaultProjectContext.ProjectFile; + var type = project.GetProjectType(); + + if(type == ProjectType.Web) + { + ReplaceSdkWithWebSdk(migrationSettings); + } + } + + private void ReplaceSdkWithWebSdk(MigrationSettings migrationSettings) + { + string csprojName = $"{GetContainingFolderName(migrationSettings.ProjectDirectory)}.csproj"; + var outputProject = Path.Combine(migrationSettings.OutputDirectory, csprojName); + + var csprojContent = File.ReadAllText(outputProject); + csprojContent = csprojContent.Replace("Sdk=\"Microsoft.NET.Sdk\"", "Sdk=\"Microsoft.NET.Sdk.Web\""); + + File.WriteAllText(outputProject, csprojContent); + } + } +} diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs index 7a31615bc..31ede5a7f 100644 --- a/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs @@ -59,10 +59,6 @@ namespace Microsoft.DotNet.Tools.Migrate var projectsToMigrate = GetProjectsToMigrate(_projectArg); var msBuildTemplatePath = _templateFile ?? temporaryDotnetNewProject.MSBuildProjectPath; - - var sdkVersion = _sdkVersion ?? temporaryDotnetNewProject.MSBuildProject.GetSdkVersion(); - - EnsureNotNull(sdkVersion, "Null Sdk Version"); MigrationReport migrationReport = null; @@ -73,7 +69,6 @@ namespace Microsoft.DotNet.Tools.Migrate var migrationSettings = new MigrationSettings( projectDirectory, outputDirectory, - sdkVersion, msBuildTemplatePath, _xprojFilePath); var projectMigrationReport = new ProjectMigrator().Migrate(migrationSettings, _skipProjectReferences); diff --git a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs index 976ce8d4a..0fceea00b 100644 --- a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs +++ b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs @@ -18,7 +18,7 @@ namespace Microsoft.DotNet.Tools.MSBuild private const string MSBuildExeName = "MSBuild.dll"; - private const string ExtensionsDirectoryName = "Extensions"; + private const string SdksDirectoryName = "Sdks"; private readonly ForwardingApp _forwardingApp; @@ -95,7 +95,7 @@ namespace Microsoft.DotNet.Tools.MSBuild return Path.Combine( AppContext.BaseDirectory, - ExtensionsDirectoryName); + SdksDirectoryName); } private static string GetRunCscPath() diff --git a/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj index 82c832ae4..f9139840a 100755 --- a/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj @@ -1,6 +1,5 @@ - - - + + Exe netcoreapp1.0 @@ -12,14 +11,7 @@ - - 1.0.1 - - - 1.0.0-alpha-20161104-2 - All - + - - + diff --git a/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj index eb2f1aaca..322e07f8d 100755 --- a/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj @@ -1,5 +1,4 @@ - - + netstandard1.4 @@ -11,14 +10,7 @@ - - 1.6 - - - 1.0.0-alpha-20161104-2 - All - + - diff --git a/src/dotnet/commands/dotnet-new/CSharp_Mstest/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_Mstest/$projectName$.csproj index 410830bca..934d54a06 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_Mstest/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_Mstest/$projectName$.csproj @@ -1,5 +1,4 @@ - - + Exe @@ -12,23 +11,10 @@ - - 1.0.1 - - - 1.0.0-alpha-20161104-2 - All - - - 15.0.0-preview-20161123-03 - - - 1.1.5-preview - - - 1.0.6-preview - + + + + - - \ No newline at end of file + diff --git a/src/dotnet/commands/dotnet-new/CSharp_Xunittest/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_Xunittest/$projectName$.csproj index ec72af7b9..8440c1803 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_Xunittest/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_Xunittest/$projectName$.csproj @@ -1,5 +1,4 @@ - - + Exe @@ -12,23 +11,10 @@ - - 1.0.1 - - - 1.0.0-alpha-20161104-2 - All - - - 15.0.0-preview-20161123-03 - - - 2.2.0-beta4-build3444 - - - 2.2.0-beta4-build1194 - + + + + - - \ No newline at end of file + diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs index 1232f4583..75b06b538 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs @@ -27,7 +27,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectDirectoryRelativeFilePaths = EnumerateFilesWithRelativePath(testProjectDirectory); var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(testProjectDirectory, outputDirectory, "1.0.0", mockProj); + var testSettings = new MigrationSettings(testProjectDirectory, outputDirectory, mockProj); var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule()); projectMigrator.Migrate(testSettings); @@ -46,7 +46,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests .Path; var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", mockProj); + var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, mockProj); var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule()); var report = projectMigrator.Migrate(testSettings); @@ -67,7 +67,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests .Path; var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", mockProj); + var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, mockProj); var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule()); var report = projectMigrator.Migrate(testSettings); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/ProjectJsonBuilder.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/ProjectJsonBuilder.cs index bbf9237df..270224b62 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/ProjectJsonBuilder.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/ProjectJsonBuilder.cs @@ -17,7 +17,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests private JObject _projectJson; private bool _baseDefined = false; - private bool _baseProjectDirectory; public ProjectJsonBuilder(TestAssetsManager testAssetsManager) { diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAssemblyInfo.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAssemblyInfo.cs index eccfee86d..3739a183f 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAssemblyInfo.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAssemblyInfo.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(projectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); _mockProject = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(projectDirectory, projectDirectory, "1.0.0", _mockProject, null); + var testSettings = new MigrationSettings(projectDirectory, projectDirectory, _mockProject, null); var testInputs = new MigrationRuleInputs( new[] {projectContext}, _mockProject, diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs index 0e9fffe6f..f9b3c683c 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs @@ -40,7 +40,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions").Path; var projectContext = ProjectContext.Create(testProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); - var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", templateProj); + var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, templateProj); var testInputs = new MigrationRuleInputs(new[] {projectContext}, templateProj, templateProj.AddItemGroup(), templateProj.AddPropertyGroup()); new MigrateBuildOptionsRule().Apply(testSettings, testInputs); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index c4a15a67c..3861d6e86 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -49,31 +49,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests privateAssetsMetadata.Value.Should().Be("All"); } - [Fact] - public void It_migrates_web_projects_to_have_web_sdk_PrivateAssets() - { - var mockProj = RunPackageDependenciesRuleOnPj(@" - { - ""buildOptions"": { - ""emitEntryPoint"": true - }, - ""dependencies"": { - ""Microsoft.AspNetCore.Mvc"" : { - ""version"": ""1.0.0"" - } - }, - ""frameworks"": { - ""netcoreapp1.0"": {} - } - }"); - - var packageRef = mockProj.Items.FirstOrDefault(i => - i.Include == "Microsoft.NET.Sdk.Web" && i.ItemType == "PackageReference"); - - packageRef.Should().NotBeNull(); - packageRef.GetMetadataWithName("PrivateAssets").Value.Should().NotBeNull().And.Be("All"); - } - [Fact] public void It_migrates_suppress_parent_array_to_PrivateAssets() { @@ -431,7 +406,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference")); } - private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple[] packageSpecs) + new private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple[] packageSpecs) { foreach (var packageSpec in packageSpecs) { @@ -449,7 +424,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } } - private void EmitsToolReferences(ProjectRootElement mockProj, params Tuple[] toolSpecs) + new private void EmitsToolReferences(ProjectRootElement mockProj, params Tuple[] toolSpecs) { foreach (var toolSpec in toolSpecs) { @@ -465,7 +440,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } } - private ProjectRootElement RunPackageDependenciesRuleOnPj(string s, string testDirectory = null) + new private ProjectRootElement RunPackageDependenciesRuleOnPj(string s, string testDirectory = null) { testDirectory = testDirectory ?? Temp.CreateDirectory().Path; return TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[] diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs index 56f104de7..b14dc4ce2 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs @@ -27,7 +27,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); + var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null); var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup()); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); @@ -51,7 +51,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); + var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null); var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup()); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); @@ -71,7 +71,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); + var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null); var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup()); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); @@ -97,7 +97,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj); + var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj); var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup()); Action action = () => new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); @@ -260,7 +260,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.Net451); var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); + var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null); var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup()); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); @@ -338,7 +338,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(appDirectory, targetFramework); var mockProj = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); + var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null); var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup()); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateRuntimeOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateRuntimeOptions.cs index 840c741b1..af6dd1f3f 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateRuntimeOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateRuntimeOptions.cs @@ -34,7 +34,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10); - var testSettings = new MigrationSettings(projectDir, projectDir, "1.0.0", default(ProjectRootElement)); + var testSettings = new MigrationSettings(projectDir, projectDir, default(ProjectRootElement)); var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null); new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs); @@ -54,7 +54,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10); - var testSettings = new MigrationSettings(projectDir, projectDir, "1.0.0", default(ProjectRootElement)); + var testSettings = new MigrationSettings(projectDir, projectDir, default(ProjectRootElement)); var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null); new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs index 2cb2b8a01..df78b2521 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs @@ -30,7 +30,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var mockProj = ProjectRootElement.Create(); - var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); + var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj); var migrationInputs = new MigrationRuleInputs( new[] { projectContext }, mockProj, @@ -54,7 +54,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory); var mockProj = ProjectRootElement.Create(); - var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); + var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj); var migrationInputs = new MigrationRuleInputs( projectContexts, mockProj, @@ -79,7 +79,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory); var mockProj = ProjectRootElement.Create(); - var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); + var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj); var migrationInputs = new MigrationRuleInputs( projectContexts, mockProj, @@ -109,7 +109,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var mockProj = ProjectRootElement.Create(); // Run BuildOptionsRule - var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); + var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj); var migrationInputs = new MigrationRuleInputs( projectContexts, mockProj, diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateWebProjects.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateWebProjects.cs new file mode 100644 index 000000000..403c2ddb6 --- /dev/null +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateWebProjects.cs @@ -0,0 +1,64 @@ +// 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.Build.Construction; +using Microsoft.DotNet.Tools.Test.Utilities; +using System.Linq; +using Xunit; +using FluentAssertions; +using Microsoft.DotNet.ProjectJsonMigration; +using Microsoft.DotNet.ProjectJsonMigration.Rules; +using System; +using System.IO; + +namespace Microsoft.DotNet.ProjectJsonMigration.Tests +{ + public class GivenThatIWantToMigrateWebProjects : PackageDependenciesTestBase + { + [Fact] + public void ItMigratesWebProjectsToHaveWebSdkInTheSdkAttribute() + { + var csprojFilePath = RunMigrateWebSdkRuleOnPj(@" + { + ""buildOptions"": { + ""emitEntryPoint"": true + }, + ""dependencies"": { + ""Microsoft.AspNetCore.Mvc"" : { + ""version"": ""1.0.0"" + } + }, + ""frameworks"": { + ""netcoreapp1.0"": {} + } + }"); + + File.ReadAllText(csprojFilePath).Should().Contain(@"Sdk=""Microsoft.NET.Sdk.Web"""); + } + + private string RunMigrateWebSdkRuleOnPj(string s, string testDirectory = null) + { + testDirectory = testDirectory ?? Temp.CreateDirectory().Path; + var csprojFilePath = Path.Combine(testDirectory, $"{GetContainingFolderName(testDirectory)}.csproj"); + + File.WriteAllText(csprojFilePath, @" + + + + "); + + TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[] + { + new MigrateWebSdkRule() + }, s, testDirectory); + + return csprojFilePath; + } + + private static string GetContainingFolderName(string projectDirectory) + { + projectDirectory = projectDirectory.TrimEnd(new char[] { '/', '\\' }); + return Path.GetFileName(projectDirectory); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/TemporaryProjectFileRuleRunner.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/TemporaryProjectFileRuleRunner.cs index dfca0ff4e..21380e997 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/TemporaryProjectFileRuleRunner.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/TemporaryProjectFileRuleRunner.cs @@ -28,7 +28,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests ProjectContext projectContext, string testDirectory, ProjectRootElement xproj) { var project = ProjectRootElement.Create(); - var testSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", project); + var testSettings = new MigrationSettings(testDirectory, testDirectory, project); var testInputs = new MigrationRuleInputs(new[] {projectContext}, project, project.AddItemGroup(), project.AddPropertyGroup(), diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs index ce99641fc..12103ab2d 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs @@ -180,7 +180,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities if (tasksToAwait.Any()) { - Task.WaitAll(tasksToAwait.ToArray()); + try + { + Task.WaitAll(tasksToAwait.ToArray()); + } + catch (System.ObjectDisposedException e) + { + taskErr = null; + + taskOut = null; + } } var result = new CommandResult( @@ -244,7 +253,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities if (tasksToAwait.Any()) { - Task.WaitAll(tasksToAwait.ToArray()); + try + { + Task.WaitAll(tasksToAwait.ToArray()); + } + catch (System.ObjectDisposedException e) + { + taskErr = null; + + taskOut = null; + } } var result = new CommandResult(