diff --git a/TestAssets/TestProjects/PJAppWithMultipleFrameworks/.noautobuild b/TestAssets/TestProjects/PJAppWithMultipleFrameworks/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/PJAppWithMultipleFrameworks/Program.cs b/TestAssets/TestProjects/PJAppWithMultipleFrameworks/Program.cs new file mode 100644 index 000000000..f5f4b6d13 --- /dev/null +++ b/TestAssets/TestProjects/PJAppWithMultipleFrameworks/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main() + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/TestProjects/PJAppWithMultipleFrameworks/project.json b/TestAssets/TestProjects/PJAppWithMultipleFrameworks/project.json new file mode 100644 index 000000000..2e09a4fd6 --- /dev/null +++ b/TestAssets/TestProjects/PJAppWithMultipleFrameworks/project.json @@ -0,0 +1,20 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true + }, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NetCore.App": { + "version": "1.0.3", + "type": "platform" + } + } + }, + "net20": {}, + "net35": {}, + "net40": {}, + "net461": {} + } +} diff --git a/TestAssets/TestProjects/PJLibWithMultipleFrameworks/.noautobuild b/TestAssets/TestProjects/PJLibWithMultipleFrameworks/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/PJLibWithMultipleFrameworks/Program.cs b/TestAssets/TestProjects/PJLibWithMultipleFrameworks/Program.cs new file mode 100644 index 000000000..78725a390 --- /dev/null +++ b/TestAssets/TestProjects/PJLibWithMultipleFrameworks/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Library +{ + public class TestLib + { + public static void Test() + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/TestProjects/PJLibWithMultipleFrameworks/project.json b/TestAssets/TestProjects/PJLibWithMultipleFrameworks/project.json new file mode 100644 index 000000000..99c97f5a8 --- /dev/null +++ b/TestAssets/TestProjects/PJLibWithMultipleFrameworks/project.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0-*", + "frameworks": { + "netstandard1.6": { + "dependencies": { + "NETStandard.Library": "1.6" + } + }, + "netstandard1.3": { + "dependencies": { + "NETStandard.Library": "1.3" + } + }, + "net451": {} + } +} diff --git a/build/Microsoft.DotNet.Cli.DependencyVersions.props b/build/Microsoft.DotNet.Cli.DependencyVersions.props index ef85a4831..1c4976512 100644 --- a/build/Microsoft.DotNet.Cli.DependencyVersions.props +++ b/build/Microsoft.DotNet.Cli.DependencyVersions.props @@ -1,9 +1,9 @@ - 15.1.0-preview-000509-03 + 15.1.0-preview-000522-02 2.0.0-rc3-61212-03 - 1.0.0-alpha-20170111-1 + 1.0.0-alpha-20170111-1 4.0.0-rc3 1.0.0-alpha-20170106-1-203 15.0.0-preview-20170106-08 diff --git a/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets b/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets index 54e67a46e..06456c755 100644 --- a/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets +++ b/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets @@ -14,7 +14,7 @@ DependsOnTargets="SetupNuGetPackagesArchiveInputsOutputs; SetupAzureBlobInformation; GenerateNuGetPackagesArchive" - Condition=" '$(UploadNuGetPackagesArchiveToAzure)' == 'true' And '$(PUBLISH_TO_AZURE_BLOB)' != '' "> + Condition=" '$(UploadNuGetPackagesArchiveToAzure)' == 'true' And '$(PUBLISH_LZMA_TO_AZURE_BLOB)' != '' "> diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs index 292f1ad47..f3e33f733 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs @@ -6,6 +6,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration internal class ConstantPackageVersions { public const string AspNetToolsVersion = "1.0.0-msbuild3-final"; + public const string AspNet110ToolsVersion = "1.1.0-msbuild3-final"; + public const string AspNetLTSPackagesVersion = "1.0.2"; + public const string EntityFrameworkLTSPackagesVersion = "1.0.2"; public const string TestSdkPackageVersion = "15.0.0-preview-20170106-08"; public const string XUnitPackageVersion = "2.2.0-beta4-build3444"; public const string XUnitRunnerPackageVersion = "2.2.0-beta4-build1194"; diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/DotnetSupportedPackageVersionsCsvProvider.cs b/src/Microsoft.DotNet.ProjectJsonMigration/DotnetSupportedPackageVersionsCsvProvider.cs new file mode 100644 index 000000000..8f2fe2bc7 --- /dev/null +++ b/src/Microsoft.DotNet.ProjectJsonMigration/DotnetSupportedPackageVersionsCsvProvider.cs @@ -0,0 +1,55 @@ +// 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.Collections.Generic; +using System.IO; + +namespace Microsoft.DotNet.ProjectJsonMigration +{ + internal class DotnetSupportedPackageVersionsCsvProvider : IDotnetSupportedPackageVersionsProvider + { + public void AddDotnetSupportedPackageVersions( + IDictionary projectDependenciesPackages) + { + var dotnetSupportedPackageVersionsPath = + Path.Combine(AppContext.BaseDirectory, "dotnet-supported-package-versions.csv"); + using (var reader = new StreamReader(File.OpenRead(dotnetSupportedPackageVersionsPath))) + { + SkipHeader(reader); + while (!reader.EndOfStream) + { + var line = reader.ReadLine(); + var values = line.Split(','); + var packageName = values[0]; + var ltsVersion = values[1]; + + if (HasVersion(ltsVersion)) + { + projectDependenciesPackages.Add( + new PackageDependencyInfo + { + Name = packageName, + Version = $"[,{ltsVersion})" + }, + new PackageDependencyInfo + { + Name = packageName, + Version = ltsVersion + }); + } + } + } + } + + private void SkipHeader(StreamReader reader) + { + reader.ReadLine(); + } + + private bool HasVersion(string version) + { + return !string.IsNullOrEmpty(version); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/IDotnetSupportedPackageVersionsProvider.cs b/src/Microsoft.DotNet.ProjectJsonMigration/IDotnetSupportedPackageVersionsProvider.cs new file mode 100644 index 000000000..bdb354992 --- /dev/null +++ b/src/Microsoft.DotNet.ProjectJsonMigration/IDotnetSupportedPackageVersionsProvider.cs @@ -0,0 +1,13 @@ +// 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.Collections.Generic; + +namespace Microsoft.DotNet.ProjectJsonMigration +{ + internal interface IDotnetSupportedPackageVersionsProvider + { + void AddDotnetSupportedPackageVersions( + IDictionary projectDependenciesPackages); + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs index d86083a27..ae5216faf 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs @@ -9,14 +9,9 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files { internal class ProjectFilesCollection { - public static readonly string[] DefaultCompileBuiltInPatterns = new[] { @"**/*.cs" }; + public static readonly string[] SdkInjectedDefaultCompileBuiltInPatterns = new[] { @"**/*.cs" }; public static readonly string[] DefaultPreprocessPatterns = new[] { @"compiler/preprocess/**/*.cs" }; public static readonly string[] DefaultSharedPatterns = new[] { @"compiler/shared/**/*.cs" }; - public static readonly string[] DefaultResourcesBuiltInPatterns = new[] { @"compiler/resources/**/*", "**/*.resx" }; - - public static readonly string[] DefaultPublishExcludePatterns = new string[0]; - public static readonly string[] DefaultContentsBuiltInPatterns = new string[0]; - public static readonly string[] DefaultBuiltInExcludePatterns = new[] { "bin/**", "obj/**", "**/*.xproj", "packages/**" }; public static readonly string PackIncludePropertyName = "packInclude"; @@ -53,11 +48,11 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files var excludeBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "excludeBuiltIn", DefaultBuiltInExcludePatterns); var excludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "exclude") .Concat(excludeBuiltIns); - var contentBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "contentBuiltIn", DefaultContentsBuiltInPatterns); - var compileBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "compileBuiltIn", DefaultCompileBuiltInPatterns); - var resourceBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "resourceBuiltIn", DefaultResourcesBuiltInPatterns); + var contentBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "contentBuiltIn"); + var compileBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "compileBuiltIn", SdkInjectedDefaultCompileBuiltInPatterns); + var resourceBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "resourceBuiltIn"); - _publishExcludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "publishExclude", DefaultPublishExcludePatterns); + _publishExcludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "publishExclude"); _sharedPatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "shared", fallbackIncluding: DefaultSharedPatterns, additionalExcluding: excludePatterns); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs index d3ac59047..57583883e 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs @@ -664,20 +664,20 @@ namespace Microsoft.DotNet.Internal.ProjectModel project, rawOptions, "compile", - defaultBuiltInInclude: ProjectFilesCollection.DefaultCompileBuiltInPatterns, + defaultBuiltInInclude: ProjectFilesCollection.SdkInjectedDefaultCompileBuiltInPatterns, defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns), EmbedInclude = GetIncludeContext( project, rawOptions, "embed", - defaultBuiltInInclude: ProjectFilesCollection.DefaultResourcesBuiltInPatterns, + defaultBuiltInInclude: null, defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns), CopyToOutputInclude = GetIncludeContext( project, rawOptions, "copyToOutput", defaultBuiltInInclude: null, - defaultBuiltInExclude: ProjectFilesCollection.DefaultPublishExcludePatterns) + defaultBuiltInExclude: null) }; } @@ -794,7 +794,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel "publishOptions", rawProject, defaultBuiltInInclude: null, - defaultBuiltInExclude: ProjectFilesCollection.DefaultPublishExcludePatterns); + defaultBuiltInExclude: null); } return null; diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.ProjectJsonMigration.csproj b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.ProjectJsonMigration.csproj index fc987fa3d..06346c987 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.ProjectJsonMigration.csproj +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.ProjectJsonMigration.csproj @@ -11,6 +11,9 @@ + + PreserveNewest + diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs deleted file mode 100644 index 2a65db310..000000000 --- a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs +++ /dev/null @@ -1,80 +0,0 @@ -// 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.Collections.Generic; - -namespace Microsoft.DotNet.ProjectJsonMigration -{ - internal class PackageDependencyInfo - { - public string Name { get; set; } - public string Version { get; set; } - public string PrivateAssets { get; set; } - } - - internal class PackageConstants - { - public const string SdkPackageName = "Microsoft.NET.Sdk"; - public const string WebSdkPackageName = "Microsoft.NET.Sdk.Web"; - public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk"; - public const string XUnitPackageName = "xunit"; - public const string XUnitRunnerPackageName = "xunit.runner.visualstudio"; - public const string MstestTestAdapterName = "MSTest.TestAdapter"; - public const string MstestTestFrameworkName = "MSTest.TestFramework"; - public const string NetStandardPackageName = "NETStandard.Library"; - public const string NetStandardPackageVersion = "1.6.0"; - public const string DotnetTestXunit = "dotnet-test-xunit"; - public const string DotnetTestMSTest = "dotnet-test-mstest"; - - public static readonly IDictionary ProjectDependencyPackages = - new Dictionary { - {"Microsoft.EntityFrameworkCore.Tools", new PackageDependencyInfo { - Name = "Microsoft.EntityFrameworkCore.Tools", - Version = ConstantPackageVersions.AspNetToolsVersion } }, - { "Microsoft.AspNetCore.Razor.Tools", null }, - { "Microsoft.AspNetCore.Razor.Design", null }, - { "Microsoft.VisualStudio.Web.CodeGenerators.Mvc", new PackageDependencyInfo { - Name = "Microsoft.VisualStudio.Web.CodeGeneration.Design", - Version = ConstantPackageVersions.AspNetToolsVersion } }, - { "Microsoft.VisualStudio.Web.CodeGeneration.Tools", null}, - { TestSdkPackageName, new PackageDependencyInfo { - Name = TestSdkPackageName, - Version = ConstantPackageVersions.TestSdkPackageVersion } }, - { XUnitPackageName, new PackageDependencyInfo { - Name = XUnitPackageName, - Version = ConstantPackageVersions.XUnitPackageVersion } }, - { XUnitRunnerPackageName, new PackageDependencyInfo { - Name = XUnitRunnerPackageName, - Version = ConstantPackageVersions.XUnitRunnerPackageVersion } }, - { MstestTestAdapterName, new PackageDependencyInfo { - Name = MstestTestAdapterName, - Version = ConstantPackageVersions.MstestTestAdapterVersion } }, - { MstestTestFrameworkName, new PackageDependencyInfo { - Name = MstestTestFrameworkName, - Version = ConstantPackageVersions.MstestTestFrameworkVersion } }, - { DotnetTestXunit, null }, - { DotnetTestMSTest, null }, - }; - - public static readonly IDictionary ProjectToolPackages = - new Dictionary { - {"Microsoft.EntityFrameworkCore.Tools", new PackageDependencyInfo { - Name = "Microsoft.EntityFrameworkCore.Tools.DotNet", - Version = ConstantPackageVersions.AspNetToolsVersion } }, - { "Microsoft.AspNetCore.Razor.Tools", null }, - { "Microsoft.VisualStudio.Web.CodeGeneration.Tools", new PackageDependencyInfo { - Name = "Microsoft.VisualStudio.Web.CodeGeneration.Tools", - Version = ConstantPackageVersions.AspNetToolsVersion } }, - { "Microsoft.DotNet.Watcher.Tools", new PackageDependencyInfo { - Name = "Microsoft.DotNet.Watcher.Tools", - Version = ConstantPackageVersions.AspNetToolsVersion } }, - { "Microsoft.Extensions.SecretManager.Tools", new PackageDependencyInfo { - Name = "Microsoft.Extensions.SecretManager.Tools", - Version = ConstantPackageVersions.AspNetToolsVersion } }, - { "Microsoft.AspNetCore.Server.IISIntegration.Tools", null}, - { "BundlerMinifier.Core", new PackageDependencyInfo { - Name = "BundlerMinifier.Core", - Version = ConstantPackageVersions.BundleMinifierToolVersion } } - }; - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectContextExtensions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectContextExtensions.cs index 66a1d7664..d1b0dac7a 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectContextExtensions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectContextExtensions.cs @@ -38,9 +38,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration return projectContexts.Any(p => p.IsFullFramework()); } + public static bool HasExeOutput(this IEnumerable projectContexts) + { + return projectContexts.Any(p => p.IsExe()); + } + + public static bool HasLibraryOutput(this IEnumerable projectContexts) + { + return projectContexts.Any(p => p.IsLibrary()); + } + public static bool IsFullFramework(this ProjectContext projectContext) { return !projectContext.TargetFramework.IsPackageBased; } + + public static bool IsExe(this ProjectContext projectContext) + { + var compilerOptions = projectContext.ProjectFile.GetCompilerOptions(null, null); + return (compilerOptions.EmitEntryPoint != null && compilerOptions.EmitEntryPoint.Value); + } + + public static bool IsLibrary(this ProjectContext projectContext) + { + var compilerOptions = projectContext.ProjectFile.GetCompilerOptions(null, null); + return (compilerOptions.EmitEntryPoint == null || !compilerOptions.EmitEntryPoint.Value); + } } } diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs index bd6e5ad1d..c0e3b0201 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs @@ -111,7 +111,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules compilerOptions => compilerOptions.OutputName != null); private IncludeContextTransform CompileFilesTransform => - new IncludeContextTransform("Compile", transformMappings: false, condition: ic => ic != null); + new IncludeContextTransform( + "Compile", + transformMappings: false, + condition: ic => ic != null, + emitBuiltInIncludes: false); private IncludeContextTransform EmbedFilesTransform => new IncludeContextTransform("EmbeddedResource", transformMappings: false, condition: ic => ic != null); @@ -396,7 +400,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules "copyToOutput", new JObject(), null, - ProjectFilesCollection.DefaultPublishExcludePatterns); + null); } private string FormatLanguageVersion(string langVersion) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index 3bfa3c356..3c07316e0 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -13,6 +13,7 @@ using Microsoft.DotNet.Internal.ProjectModel; using Microsoft.DotNet.Tools.Common; using NuGet.Frameworks; using NuGet.LibraryModel; +using NuGet.Versioning; namespace Microsoft.DotNet.ProjectJsonMigration.Rules { @@ -22,10 +23,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules private readonly ProjectDependencyFinder _projectDependencyFinder; private string _projectDirectory; + private SupportedPackageVersions _supportedPackageVersions; + public MigratePackageDependenciesAndToolsRule(ITransformApplicator transformApplicator = null) { _transformApplicator = transformApplicator ?? new TransformApplicator(); _projectDependencyFinder = new ProjectDependencyFinder(); + + _supportedPackageVersions = new SupportedPackageVersions(); } public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs) @@ -91,7 +96,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { - Name = PackageConstants.TestSdkPackageName, + Name = SupportedPackageVersions.TestSdkPackageName, Version = ConstantPackageVersions.TestSdkPackageVersion }), noFrameworkPackageReferenceItemGroup, @@ -103,7 +108,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { - Name = PackageConstants.XUnitPackageName, + Name = SupportedPackageVersions.XUnitPackageName, Version = ConstantPackageVersions.XUnitPackageVersion }), noFrameworkPackageReferenceItemGroup, @@ -113,7 +118,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { - Name = PackageConstants.XUnitRunnerPackageName, + Name = SupportedPackageVersions.XUnitRunnerPackageName, Version = ConstantPackageVersions.XUnitRunnerPackageVersion }), noFrameworkPackageReferenceItemGroup, @@ -125,7 +130,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { - Name = PackageConstants.MstestTestAdapterName, + Name = SupportedPackageVersions.MstestTestAdapterName, Version = ConstantPackageVersions.MstestTestAdapterVersion }), noFrameworkPackageReferenceItemGroup, @@ -135,7 +140,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { - Name = PackageConstants.MstestTestFrameworkName, + Name = SupportedPackageVersions.MstestTestFrameworkName, Version = ConstantPackageVersions.MstestTestFrameworkVersion }), noFrameworkPackageReferenceItemGroup, @@ -144,14 +149,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules break; case ProjectType.Library: if (!project.HasDependency( - (dep) => dep.Name.Trim().ToLower() == PackageConstants.NetStandardPackageName.ToLower())) + (dep) => dep.Name.Trim().ToLower() == SupportedPackageVersions.NetStandardPackageName.ToLower())) { _transformApplicator.Execute( PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { - Name = PackageConstants.NetStandardPackageName, - Version = PackageConstants.NetStandardPackageVersion + Name = SupportedPackageVersions.NetStandardPackageName, + Version = SupportedPackageVersions.NetStandardPackageVersion }), noFrameworkPackageReferenceItemGroup, mergeExisting: true); @@ -208,7 +213,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules _transformApplicator.Execute( ToolTransform().Transform(ToPackageDependencyInfo( tool, - PackageConstants.ProjectToolPackages)), + SupportedPackageVersions.ProjectToolPackages)), itemGroup, mergeExisting: true); } @@ -266,7 +271,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules _transformApplicator.Execute( transform.Transform(ToPackageDependencyInfo( packageDependency, - PackageConstants.ProjectDependencyPackages)), + _supportedPackageVersions.ProjectDependencyPackages)), itemGroup, mergeExisting: true); } @@ -274,21 +279,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules private PackageDependencyInfo ToPackageDependencyInfo( ProjectLibraryDependency dependency, - IDictionary dependencyToVersionMap) + IDictionary dependencyToVersionMap) { var name = dependency.Name; var version = dependency.LibraryRange?.VersionRange?.OriginalString; + var minRange = dependency.LibraryRange?.VersionRange?.ToNonSnapshotRange().MinVersion; - if (dependencyToVersionMap.ContainsKey(name)) + var possibleMappings = + dependencyToVersionMap.Where(c => c.Key.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); + if (possibleMappings.Any() && !string.IsNullOrEmpty(version)) { - var dependencyInfo = dependencyToVersionMap[name]; - if (dependencyInfo == null) + var possibleVersions = possibleMappings.Select(p => VersionRange.Parse(p.Key.Version)); + var matchVersion = possibleVersions.FirstOrDefault(p => p.Satisfies(minRange)); + if (matchVersion != null) { - return null; - } + var dependencyInfo = possibleMappings.First(c => + c.Key.Version.Equals(matchVersion.OriginalString, StringComparison.OrdinalIgnoreCase)).Value; - name = dependencyInfo.Name; - version = dependencyInfo.Version; + if (dependencyInfo == null) + { + return null; + } + + name = dependencyInfo.Name; + version = dependencyInfo.Version; + } } return new PackageDependencyInfo diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateScriptsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateScriptsRule.cs index 789a05c69..152e66a7e 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateScriptsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateScriptsRule.cs @@ -23,6 +23,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs) { var csproj = migrationRuleInputs.OutputMSBuildProject; + var commonPropertyGroup = migrationRuleInputs.CommonPropertyGroup; var projectContext = migrationRuleInputs.DefaultProjectContext; var scripts = projectContext.ProjectFile.Scripts; @@ -30,6 +31,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules { MigrateScriptSet( csproj, + commonPropertyGroup, scriptSet.Value, scriptSet.Key, migrationRuleInputs.IsMultiTFM); @@ -38,6 +40,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules public ProjectTargetElement MigrateScriptSet( ProjectRootElement csproj, + ProjectPropertyGroupElement commonPropertyGroup, IEnumerable scriptCommands, string scriptSetName, bool isMultiTFM) @@ -49,6 +52,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules { continue; } + else if (IsRazorPrecompilationCommand(scriptCommand)) + { + EnableRazorCompilationOnPublish(commonPropertyGroup); + continue; + } AddExec(target, FormatScriptCommand(scriptCommand)); } @@ -94,6 +102,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules return command.Contains("dotnet publish-iis"); } + private static bool IsRazorPrecompilationCommand(string command) + { + return command.Contains("dotnet razor-precompile"); + } + + private static void EnableRazorCompilationOnPublish(ProjectPropertyGroupElement commonPropertyGroup) + { + commonPropertyGroup.AddProperty("MvcRazorCompileOnPublish", "true"); + } + private bool IsPathRootedForAnyOS(string path) { return path.StartsWith("/") || path.Substring(1).StartsWith(":\\"); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateTFMRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateTFMRule.cs index 20e11005a..188cc286a 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateTFMRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateTFMRule.cs @@ -85,7 +85,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules { var packageRefs = outputMSBuildProject .Items - .Where(i => i.ItemType == "PackageReference" && i.Include != PackageConstants.SdkPackageName) + .Where(i => i.ItemType == "PackageReference" && i.Include != SupportedPackageVersions.SdkPackageName) .ToList(); foreach (var packageRef in packageRefs) @@ -133,13 +133,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules "RuntimeIdentifiers", projectContexts => RuntimeIdentifiers, projectContexts => !projectContexts.HasRuntimes() && + !projectContexts.HasLibraryOutput() && projectContexts.HasBothCoreAndFullFrameworkTFMs()); private AddPropertyTransform> RuntimeIdentifierTransform => new AddPropertyTransform>( "RuntimeIdentifier", projectContexts => "win7-x86", - projectContexts => !projectContexts.HasRuntimes() && projectContexts.HasFullFrameworkTFM()) + projectContexts => !projectContexts.HasRuntimes() && + !projectContexts.HasLibraryOutput() && + projectContexts.HasFullFrameworkTFM()) .WithMSBuildCondition(projectContexts => { string msBuildCondition = null; diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/SupportedPackageVersions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/SupportedPackageVersions.cs new file mode 100644 index 000000000..28ff6336f --- /dev/null +++ b/src/Microsoft.DotNet.ProjectJsonMigration/SupportedPackageVersions.cs @@ -0,0 +1,269 @@ +// 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.Collections.Generic; +using System.IO; + +namespace Microsoft.DotNet.ProjectJsonMigration +{ + internal class PackageDependencyInfo + { + public string Name { get; set; } + public string Version { get; set; } + public string PrivateAssets { get; set; } + } + + internal class SupportedPackageVersions + { + public const string SdkPackageName = "Microsoft.NET.Sdk"; + public const string WebSdkPackageName = "Microsoft.NET.Sdk.Web"; + public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk"; + public const string XUnitPackageName = "xunit"; + public const string XUnitRunnerPackageName = "xunit.runner.visualstudio"; + public const string MstestTestAdapterName = "MSTest.TestAdapter"; + public const string MstestTestFrameworkName = "MSTest.TestFramework"; + public const string NetStandardPackageName = "NETStandard.Library"; + public const string NetStandardPackageVersion = "1.6.0"; + public const string DotnetTestXunit = "dotnet-test-xunit"; + public const string DotnetTestMSTest = "dotnet-test-mstest"; + + public readonly IDictionary ProjectDependencyPackages; + + public static readonly IDictionary ProjectToolPackages = + new Dictionary { + { + new PackageDependencyInfo + { + Name = "Microsoft.EntityFrameworkCore.Tools", + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = "Microsoft.EntityFrameworkCore.Tools.DotNet", + Version = ConstantPackageVersions.AspNetToolsVersion + } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.AspNetCore.Razor.Tools", + Version = "[1.0.0-*,)" + }, + null + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools", + Version = "[1.0.0-*,)" + }, + null + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.VisualStudio.Web.CodeGeneration.Tools", + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = "Microsoft.VisualStudio.Web.CodeGeneration.Tools", + Version = ConstantPackageVersions.AspNetToolsVersion + } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.DotNet.Watcher.Tools", + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = "Microsoft.DotNet.Watcher.Tools", + Version = ConstantPackageVersions.AspNetToolsVersion + } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.Extensions.SecretManager.Tools", + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = "Microsoft.Extensions.SecretManager.Tools", + Version = ConstantPackageVersions.AspNetToolsVersion + } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.AspNetCore.Server.IISIntegration.Tools", + Version = "[1.0.0-*,)" + }, + null + }, + { + new PackageDependencyInfo{ + Name = "BundlerMinifier.Core", + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = "BundlerMinifier.Core", + Version = ConstantPackageVersions.BundleMinifierToolVersion + } + } + }; + + public SupportedPackageVersions() + { + ProjectDependencyPackages = + new Dictionary { + { + new PackageDependencyInfo { + Name = "Microsoft.EntityFrameworkCore.Tools", + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = "Microsoft.EntityFrameworkCore.Tools", + Version = ConstantPackageVersions.AspNetToolsVersion } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.AspNetCore.Razor.Tools", + Version = "[1.0.0-*,)" + }, + null + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.AspNetCore.Razor.Design", + Version = "[1.0.0-*,)" + }, + null + }, + // I hate to do this, but ordering here matters. The higher version needs to come first, otherwise + // the lower version mapping will match to it. + { + new PackageDependencyInfo + { + Name = "Microsoft.VisualStudio.Web.CodeGenerators.Mvc", + Version = "[1.1.0-*,)" + }, + new PackageDependencyInfo + { + Name = "Microsoft.VisualStudio.Web.CodeGeneration.Design", + Version = ConstantPackageVersions.AspNet110ToolsVersion + } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.VisualStudio.Web.CodeGenerators.Mvc", + Version = "[1.0.0-*,1.1.0)" + }, + new PackageDependencyInfo + { + Name = "Microsoft.VisualStudio.Web.CodeGeneration.Design", + Version = ConstantPackageVersions.AspNetToolsVersion + } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design", + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation", + Version = ConstantPackageVersions.AspNet110ToolsVersion + } + }, + { + new PackageDependencyInfo + { + Name = "Microsoft.VisualStudio.Web.CodeGeneration.Tools", + Version = "[1.0.0-*,)" + }, + null + }, + { + new PackageDependencyInfo + { + Name = TestSdkPackageName, + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo + { + Name = TestSdkPackageName, + Version = ConstantPackageVersions.TestSdkPackageVersion + } + }, + { + new PackageDependencyInfo + { + Name = XUnitPackageName, + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo + { + Name = XUnitPackageName, + Version = ConstantPackageVersions.XUnitPackageVersion + } + }, + { + new PackageDependencyInfo + { + Name = XUnitRunnerPackageName, + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = XUnitRunnerPackageName, + Version = ConstantPackageVersions.XUnitRunnerPackageVersion + } + }, + { + new PackageDependencyInfo + { + Name = MstestTestAdapterName, + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo + { + Name = MstestTestAdapterName, + Version = ConstantPackageVersions.MstestTestAdapterVersion + } + }, + { + new PackageDependencyInfo + { + Name = MstestTestFrameworkName, + Version = "[1.0.0-*,)" + }, + new PackageDependencyInfo { + Name = MstestTestFrameworkName, + Version = ConstantPackageVersions.MstestTestFrameworkVersion + } + }, + { + new PackageDependencyInfo + { + Name = DotnetTestXunit, + Version = "[1.0.0-*,)" + }, + null + }, + { + new PackageDependencyInfo + { + Name = DotnetTestMSTest, + Version = "[1.0.0-*,)" + }, + null + } + }; + + new DotnetSupportedPackageVersionsCsvProvider() + .AddDotnetSupportedPackageVersions(ProjectDependencyPackages); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/dotnet-supported-package-versions.csv b/src/Microsoft.DotNet.ProjectJsonMigration/dotnet-supported-package-versions.csv new file mode 100644 index 000000000..6cd457775 --- /dev/null +++ b/src/Microsoft.DotNet.ProjectJsonMigration/dotnet-supported-package-versions.csv @@ -0,0 +1,311 @@ +Id,LtsVersion,CurrentVersion +Microsoft.NETCore.App,1.0.3,1.1.0 +Microsoft.AspNetCore,1.0.3,1.1.0 +Microsoft.AspNetCore.Authentication,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.Cookies,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.Facebook,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.Google,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.JwtBearer,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.MicrosoftAccount,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.OAuth,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.OpenIdConnect,1.0.1,1.1.0 +Microsoft.AspNetCore.Authentication.Twitter,1.0.1,1.1.0 +Microsoft.AspNetCore.CookiePolicy,1.0.1,1.1.0 +Microsoft.AspNetCore.Cors,1.0.1,1.1.0 +Microsoft.AspNetCore.DataProtection,1.0.1,1.1.0 +Microsoft.AspNetCore.DataProtection.Extensions,1.0.1,1.1.0 +Microsoft.AspNetCore.DataProtection.SystemWeb,1.0.1,1.1.0 +Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore,1.0.1,1.1.0 +Microsoft.AspNetCore.Hosting.WindowsServices,1.0.1,1.1.0 +Microsoft.AspNetCore.Html.Abstractions,1.0.1,1.1.0 +Microsoft.AspNetCore.Identity.EntityFrameworkCore,1.0.1,1.1.0 +Microsoft.AspNetCore.MiddlewareAnalysis,1.0.1,1.1.0 +Microsoft.AspNetCore.Mvc,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.Abstractions,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.ApiExplorer,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.Formatters.Xml,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.WebApiCompatShim,1.0.2,1.1.0 +Microsoft.AspNetCore.Owin,1.0.1,1.1.0 +Microsoft.AspNetCore.Routing,1.0.2,1.1.0 +Microsoft.AspNetCore.Routing.Abstractions,1.0.2,1.1.0 +Microsoft.AspNetCore.Server.Kestrel.Https,1.0.2,1.1.0 +Microsoft.AspNetCore.Session,1.0.1,1.1.0 +Microsoft.AspNetCore.StaticFiles,1.0.1,1.1.0 +Microsoft.AspNetCore.TestHost,1.0.1,1.1.0 +Microsoft.Data.Sqlite,1.0.1,1.1.0 +Microsoft.EntityFrameworkCore,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.Design,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.InMemory,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.Relational,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.Relational.Design,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.Sqlite,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.Sqlite.Design,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.SqlServer,1.0.2,1.1.0 +Microsoft.EntityFrameworkCore.SqlServer.Design,1.0.2,1.1.0 +Microsoft.Extensions.Caching.Memory,1.0.1,1.1.0 +Microsoft.Extensions.Caching.Redis,1.0.1,1.1.0 +Microsoft.Extensions.Caching.SqlServer,1.0.1,1.1.0 +Microsoft.Extensions.CommandLineUtils,1.0.1,1.1.0 +Microsoft.Extensions.Configuration,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.Binder,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.CommandLine,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.EnvironmentVariables,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.FileExtensions,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.Ini,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.Json,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.UserSecrets,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.Xml,1.0.1,1.1.0 +Microsoft.Extensions.DependencyInjection,1.0.1,1.1.0 +Microsoft.Extensions.DiagnosticAdapter,1.0.1,1.1.0 +Microsoft.Extensions.FileProviders.Composite,1.0.1,1.1.0 +Microsoft.Extensions.FileProviders.Embedded,1.0.1,1.1.0 +Microsoft.Extensions.FileProviders.Physical,1.0.1,1.1.0 +Microsoft.Extensions.FileSystemGlobbing,1.0.1,1.1.0 +Microsoft.Extensions.Globalization.CultureInfoCache,1.0.1,1.1.0 +Microsoft.Extensions.Localization,1.0.1,1.1.0 +Microsoft.Extensions.Logging,1.0.1,1.1.0 +Microsoft.Extensions.Logging.Console,1.0.1,1.1.0 +Microsoft.Extensions.Logging.Debug,1.0.1,1.1.0 +Microsoft.Extensions.Logging.Filter,1.0.1,1.1.0 +Microsoft.Extensions.Logging.TraceSource,1.0.1,1.1.0 +Microsoft.VisualStudio.Web.BrowserLink,1.0.0,1.0.0 +Microsoft.VisualStudio.Web.BrowserLink.Loader,14.0.1,14.1.0 +Microsoft.AspNetCore.AzureAppServicesIntegration,,1.0.0 +Microsoft.AspNetCore.DataProtection.AzureStorage,,1.0.0 +Microsoft.AspNetCore.Localization.Routing,,1.1.0 +Microsoft.AspNetCore.Rewrite,,1.0.0 +Microsoft.AspNetCore.ResponseCaching,,1.1.0 +Microsoft.AspNetCore.ResponseCompression,,1.0.0 +Microsoft.AspNetCore.WebSockets,,1.0.0 +Microsoft.Extensions.Logging.AzureAppServices,,1.0.0 +Microsoft.Extensions.Configuration.AzureKeyVault,,1.0.0 +Microsoft.Extensions.Logging.EventSource,,1.1.0 +System.ServiceModel.Duplex,4.0.1,4.3.0 +System.ServiceModel.Http,4.1.0,4.3.0 +System.ServiceModel.NetTcp,4.1.0,4.3.0 +System.ServiceModel.Security,4.0.1,4.3.0 +Libuv,1.9.1,1.9.1 +Microsoft.AspNet.WebApi.Client,5.2.2,5.2.2 +Microsoft.AspNetCore.Antiforgery,1.0.2,1.1.0 +Microsoft.AspNetCore.Authorization,1.0.1,1.1.0 +Microsoft.AspNetCore.Cryptography.Internal,1.0.1,1.1.0 +Microsoft.AspNetCore.Cryptography.KeyDerivation,1.0.1,1.1.0 +Microsoft.AspNetCore.DataProtection.Abstractions,1.0.1,1.1.0 +Microsoft.AspNetCore.Diagnostics,1.0.1,1.1.0 +Microsoft.AspNetCore.Diagnostics.Abstractions,1.0.1,1.1.0 +Microsoft.AspNetCore.Hosting,1.0.1,1.1.0 +Microsoft.AspNetCore.Hosting.Abstractions,1.0.1,1.1.0 +Microsoft.AspNetCore.Hosting.Server.Abstractions,1.0.1,1.1.0 +Microsoft.AspNetCore.Http,1.0.1,1.1.0 +Microsoft.AspNetCore.Http.Abstractions,1.0.1,1.1.0 +Microsoft.AspNetCore.Http.Extensions,1.0.1,1.1.0 +Microsoft.AspNetCore.Http.Features,1.0.1,1.1.0 +Microsoft.AspNetCore.HttpOverrides,1.0.1,1.1.0 +Microsoft.AspNetCore.Identity,1.0.1,1.1.0 +Microsoft.AspNetCore.JsonPatch,1.0.0,1.1.0 +Microsoft.AspNetCore.Localization,1.0.1,1.1.0 +Microsoft.AspNetCore.Mvc.Core,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.Cors,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.DataAnnotations,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.Formatters.Json,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.Localization,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.Razor,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.Razor.Host,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.TagHelpers,1.0.2,1.1.0 +Microsoft.AspNetCore.Mvc.ViewFeatures,1.0.2,1.1.0 +Microsoft.AspNetCore.Razor,1.0.1,1.1.0 +Microsoft.AspNetCore.Razor.Runtime,1.0.1,1.1.0 +Microsoft.AspNetCore.Server.IISIntegration,1.0.1,1.1.0 +Microsoft.AspNetCore.Server.Kestrel,1.0.2,1.1.0 +Microsoft.AspNetCore.WebUtilities,1.0.1,1.1.0 +Microsoft.Bcl,1.1.9,1.1.9 +Microsoft.Bcl.Build,1.0.14,1.0.14 +Microsoft.CodeAnalysis.Analyzers,1.1.0,1.1.0 +Microsoft.CodeAnalysis.Common,1.3.0,1.3.0 +Microsoft.CodeAnalysis.CSharp,1.3.0,1.3.0 +Microsoft.CodeAnalysis.VisualBasic,1.3.0,1.3.0 +Microsoft.CSharp,4.0.1,4.3.0 +Microsoft.DotNet.InternalAbstractions,1.0.0, +Microsoft.Extensions.Caching.Abstractions,1.0.1,1.1.0 +Microsoft.Extensions.Configuration.Abstractions,1.0.1,1.1.0 +Microsoft.Extensions.DependencyInjection.Abstractions,1.0.1,1.1.0 +Microsoft.Extensions.DependencyModel,1.0.0,1.1.0 +Microsoft.Extensions.FileProviders.Abstractions,1.0.1,1.1.0 +Microsoft.Extensions.Localization.Abstractions,1.0.1,1.1.0 +Microsoft.Extensions.Logging.Abstractions,1.0.1,1.1.0 +Microsoft.Extensions.ObjectPool,1.0.1,1.1.0 +Microsoft.Extensions.Options,1.0.1,1.1.0 +Microsoft.Extensions.Options.ConfigurationExtensions,1.0.1,1.1.0 +Microsoft.Extensions.PlatformAbstractions,1.0.0,1.1.0 +Microsoft.Extensions.Primitives,1.0.1,1.1.0 +Microsoft.Extensions.WebEncoders,1.0.1,1.1.0 +Microsoft.IdentityModel.Logging,1.0.0,1.1.0 +Microsoft.IdentityModel.Protocols,2.0.0,2.1.0 +Microsoft.IdentityModel.Protocols.OpenIdConnect,2.0.0,2.1.0 +Microsoft.IdentityModel.Tokens,5.0.0,5.1.0 +Microsoft.Net.Http,2.2.22,2.2.22 +Microsoft.Net.Http.Headers,1.0.1,1.1.0 +Microsoft.NETCore.DotNetHost,1.0.1,1.1.0 +Microsoft.NETCore.DotNetHostPolicy,1.0.3,1.1.0 +Microsoft.NETCore.DotNetHostResolver,1.0.1,1.1.0 +Microsoft.NETCore.Jit,1.0.5,1.1.0 +Microsoft.NETCore.Platforms,1.0.2,1.1.0 +Microsoft.NETCore.Runtime.CoreCLR,1.0.5,1.1.0 +Microsoft.NETCore.Targets,1.0.1,1.1.0 +Microsoft.NETCore.Windows.ApiSets,1.0.1,1.0.1 +Microsoft.VisualBasic,10.0.1,10.1.0 +Microsoft.Win32.Primitives,4.0.1,4.3.0 +Microsoft.Win32.Registry,4.0.0,4.3.0 +NETStandard.Library,1.6.0,1.6.1 +Newtonsoft.Json,9.0.1,9.0.1 +Remotion.Linq,2.1.1,2.1.1 +runtime.native.System,4.0.0,4.3.0 +runtime.native.System.Data.SqlClient.sni,4.0.0,4.3.0 +runtime.native.System.IO.Compression,4.1.0,4.3.0 +runtime.native.System.Net.Http,4.0.1,4.3.0 +runtime.native.System.Net.Security,4.0.1,4.3.0 +runtime.native.System.Security.Cryptography,4.0.0, +runtime.win7-x64.runtime.native.System.Data.SqlClient.sni,4.0.1,4.3.0 +runtime.win7-x86.runtime.native.System.Data.SqlClient.sni,4.0.1,4.3.0 +SQLite,3.13.0,3.13.0 +System.AppContext,4.1.0,4.3.0 +System.Buffers,4.0.0,4.3.0 +System.Collections,4.0.11,4.3.0 +System.Collections.Concurrent,4.0.12,4.3.0 +System.Collections.Immutable,1.2.0,1.3.0 +System.Collections.NonGeneric,4.0.1,4.3.0 +System.Collections.Specialized,4.0.1,4.3.0 +System.ComponentModel,4.0.1,4.3.0 +System.ComponentModel.Annotations,4.1.0,4.3.0 +System.ComponentModel.EventBasedAsync,4.0.11,4.3.0 +System.ComponentModel.Primitives,4.1.0,4.3.0 +System.ComponentModel.TypeConverter,4.1.0,4.3.0 +System.Console,4.0.0,4.3.0 +System.Data.Common,4.1.0,4.3.0 +System.Data.SqlClient,4.1.0,4.3.0 +System.Diagnostics.Contracts,4.0.1,4.3.0 +System.Diagnostics.Debug,4.0.11,4.3.0 +System.Diagnostics.DiagnosticSource,4.0.0,4.3.0 +System.Diagnostics.FileVersionInfo,4.0.0,4.0.0 +System.Diagnostics.Process,4.1.0,4.3.0 +System.Diagnostics.StackTrace,4.0.1,4.3.0 +System.Diagnostics.Tools,4.0.1,4.3.0 +System.Diagnostics.TraceSource,4.0.0,4.3.0 +System.Diagnostics.Tracing,4.1.0,4.3.0 +System.Dynamic.Runtime,4.0.11,4.3.0 +System.Globalization,4.0.11,4.3.0 +System.Globalization.Calendars,4.0.1,4.3.0 +System.Globalization.Extensions,4.0.1,4.3.0 +System.IdentityModel.Tokens.Jwt,5.0.0,5.1.0 +System.Interactive.Async,3.0.0,3.0.0 +System.IO,4.1.0,4.3.0 +System.IO.Compression,4.1.0,4.3.0 +System.IO.Compression.ZipFile,4.0.1,4.3.0 +System.IO.FileSystem,4.0.1,4.3.0 +System.IO.FileSystem.Primitives,4.0.1,4.3.0 +System.IO.FileSystem.Watcher,4.0.0,4.3.0 +System.IO.MemoryMappedFiles,4.0.0,4.3.0 +System.IO.Pipes,4.0.0,4.3.0 +System.IO.UnmanagedMemoryStream,4.0.1,4.3.0 +System.Linq,4.1.0,4.3.0 +System.Linq.Expressions,4.1.0,4.3.0 +System.Linq.Parallel,4.0.1,4.3.0 +System.Linq.Queryable,4.0.1,4.3.0 +System.Net.Http,4.1.1,4.3.0 +System.Net.NameResolution,4.0.0,4.3.0 +System.Net.Primitives,4.0.11,4.3.0 +System.Net.Requests,4.0.11,4.3.0 +System.Net.Security,4.0.0,4.3.0 +System.Net.Sockets,4.1.0,4.3.0 +System.Net.WebHeaderCollection,4.0.1,4.3.0 +System.Net.WebSockets,4.0.0,4.3.0 +System.Net.WebSockets.Client,4.0.0,4.3.0 +System.Numerics.Vectors,4.1.1,4.3.0 +System.ObjectModel,4.0.12,4.3.0 +System.Private.DataContractSerialization,4.1.1,4.3.0 +System.Private.ServiceModel,4.1.0,4.3.0 +System.Reflection,4.1.0,4.3.0 +System.Reflection.DispatchProxy,4.0.1,4.3.0 +System.Reflection.Emit,4.0.1,4.3.0 +System.Reflection.Emit.ILGeneration,4.0.1,4.3.0 +System.Reflection.Emit.Lightweight,4.0.1,4.3.0 +System.Reflection.Extensions,4.0.1,4.3.0 +System.Reflection.Metadata,1.3.0,1.4.1 +System.Reflection.Primitives,4.0.1,4.3.0 +System.Reflection.TypeExtensions,4.1.0,4.3.0 +System.Resources.Reader,4.0.0,4.3.0 +System.Resources.ResourceManager,4.0.1,4.3.0 +System.Runtime,4.1.0,4.3.0 +System.Runtime.Extensions,4.1.0,4.3.0 +System.Runtime.Handles,4.0.1,4.3.0 +System.Runtime.InteropServices,4.1.0,4.3.0 +System.Runtime.InteropServices.RuntimeInformation,4.0.0,4.3.0 +System.Runtime.Loader,4.0.0,4.3.0 +System.Runtime.Numerics,4.0.1,4.3.0 +System.Runtime.Serialization.Primitives,4.1.1,4.3.0 +System.Runtime.Serialization.Xml,4.1.1,4.3.0 +System.Security.Claims,4.0.1,4.3.0 +System.Security.Cryptography.Algorithms,4.2.0,4.3.0 +System.Security.Cryptography.Cng,4.2.0,4.3.0 +System.Security.Cryptography.Csp,4.0.0,4.3.0 +System.Security.Cryptography.Encoding,4.0.0,4.3.0 +System.Security.Cryptography.OpenSsl,4.0.0,4.3.0 +System.Security.Cryptography.Primitives,4.0.0,4.3.0 +System.Security.Cryptography.X509Certificates,4.1.0,4.3.0 +System.Security.Principal,4.0.1,4.3.0 +System.Security.Principal.Windows,4.0.0,4.3.0 +System.ServiceModel.Primitives,4.1.0,4.3.0 +System.Text.Encoding,4.0.11,4.3.0 +System.Text.Encoding.CodePages,4.0.1,4.3.0 +System.Text.Encoding.Extensions,4.0.11,4.3.0 +System.Text.Encodings.Web,4.0.0,4.3.0 +System.Text.RegularExpressions,4.1.0,4.3.0 +System.Threading,4.0.11,4.3.0 +System.Threading.Overlapped,4.0.1,4.3.0 +System.Threading.Tasks,4.0.11,4.3.0 +System.Threading.Tasks.Dataflow,4.6.0,4.7.0 +System.Threading.Tasks.Extensions,4.0.0,4.3.0 +System.Threading.Tasks.Parallel,4.0.1,4.3.0 +System.Threading.Thread,4.0.0,4.3.0 +System.Threading.ThreadPool,4.0.10,4.3.0 +System.Threading.Timer,4.0.1,4.3.0 +System.Xml.ReaderWriter,4.0.11,4.3.0 +System.Xml.XDocument,4.0.11,4.3.0 +System.Xml.XmlDocument,4.0.1,4.3.0 +System.Xml.XmlSerializer,4.0.11,4.3.0 +System.Xml.XPath,4.0.1,4.0.1 +System.Xml.XPath.XDocument,4.0.1,4.0.1 +Microsoft.AspNetCore.ResponseCaching.Abstractions,,1.1.0 +Microsoft.Azure.KeyVault,,2.0.2-preview +Microsoft.Azure.KeyVault.WebKey,,2.0.0-preview +Microsoft.Data.Edm,,5.6.4 +Microsoft.Data.OData,,5.6.4 +Microsoft.Data.Services.Client,,5.6.4 +Microsoft.DiaSymReader.Native,,1.4.0 +Microsoft.DotNet.PlatformAbstractions,,1.1.0 +Microsoft.IdentityModel.Clients.ActiveDirectory,,3.13.5 +Microsoft.Rest.ClientRuntime,,2.3.2 +Microsoft.Rest.ClientRuntime.Azure,,3.3.1 +runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.fedora.23-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.fedora.24-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.native.System.Security.Cryptography.Apple,,4.3.0 +runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.opensuse.13.2-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.opensuse.42.1-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.osx.10.10-x64.runtime.native.System.Security.Cryptography.Apple,,4.3.0 +runtime.osx.10.10-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.rhel.7-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.ubuntu.14.04-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl,,4.3.0 +Serilog,,2.3.0 +Serilog.Extensions.Logging,,1.0.0 +Serilog.Sinks.File,,3.1.0 +Serilog.Sinks.PeriodicBatching,,2.0.0 +Serilog.Sinks.RollingFile,,3.1.0 +StackExchange.Redis.StrongName,,1.1.605 +System.Runtime.CompilerServices.Unsafe,,4.3.0 +System.Runtime.Serialization.Json,,4.0.2 +System.Spatial,,5.6.4 +WindowsAzure.Storage,,7.2.1 \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs index 60db53fc2..65630c2da 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs @@ -30,8 +30,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms itemName, includeContext => { - var fullIncludeSet = includeContext.IncludePatterns.OrEmptyIfNull() - .Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); + var fullIncludeSet = includeContext.IncludePatterns.OrEmptyIfNull(); + if (_emitBuiltInIncludes) + { + fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); + } return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath); }, @@ -49,7 +52,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms ( (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0) || - (includeContext.BuiltInsInclude != null && includeContext.BuiltInsInclude.Count > 0) + (_emitBuiltInIncludes && + includeContext.BuiltInsInclude != null && + includeContext.BuiltInsInclude.Count > 0) ); }); @@ -63,15 +68,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms private readonly string _itemName; private bool _transformMappings; + private bool _emitBuiltInIncludes; private readonly List> _metadata = new List>(); public IncludeContextTransform( string itemName, bool transformMappings = true, - Func condition = null) : base(condition) + Func condition = null, + bool emitBuiltInIncludes = true) : base(condition) { _itemName = itemName; _transformMappings = transformMappings; + _emitBuiltInIncludes = emitBuiltInIncludes; _mappingsToTransfrom = (addItemTransform, targetPath) => { diff --git a/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs b/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs index c733e0b8b..bf8f2b0a6 100644 --- a/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs +++ b/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Tools.Migrate return projectRootElement .Items .Where(i => i.ItemType == "PackageReference") - .First(i => i.Include == PackageConstants.SdkPackageName) + .First(i => i.Include == SupportedPackageVersions.SdkPackageName) .GetMetadataWithName("version").Value; } } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs index 81d245811..50819632c 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs @@ -582,7 +582,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests private static IEnumerable GetDefaultExcludePatterns(string group) { var defaultExcludePatterns = new List(group == "copyToOutput" ? - ProjectFilesCollection.DefaultPublishExcludePatterns : + Enumerable.Empty() : ProjectFilesCollection.DefaultBuiltInExcludePatterns); if (group == "embed") @@ -595,9 +595,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests private static IEnumerable GetDefaultIncludePatterns(string group) { - return group == "compile" ? ProjectFilesCollection.DefaultCompileBuiltInPatterns - : group == "embed" ? ProjectFilesCollection.DefaultResourcesBuiltInPatterns - : Enumerable.Empty(); + return Enumerable.Empty(); } private static void VerifyContentMetadata(ProjectItemElement item) diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackagesToTheirLTSVersions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackagesToTheirLTSVersions.cs new file mode 100644 index 000000000..c8ab19dde --- /dev/null +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackagesToTheirLTSVersions.cs @@ -0,0 +1,240 @@ +// 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.Linq; +using Xunit; +using FluentAssertions; +using System; + +namespace Microsoft.DotNet.ProjectJsonMigration.Tests +{ + public class GivenThatIWantToMigratePackagesToTheirLTSVersions : PackageDependenciesTestBase + { + [Theory] + [InlineData("Microsoft.NETCore.App", "1.0.0", "Microsoft.NETCore.App", "1.0.3")] + [InlineData("Microsoft.NETCore.App", "1.0.3-preview2", "Microsoft.NETCore.App", "1.0.3")] + [InlineData("NETStandard.Library", "1.4.0", "NETStandard.Library", "1.6.0")] + public void ItUpliftsMetaPackages( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + + [Theory] + [InlineData("NETStandard.Library", "1.6.2-*", "NETStandard.Library", "1.6.2-*")] + [InlineData("System.Text.Encodings.Web", "4.4.0-*", "System.Text.Encodings.Web", "4.4.0-*")] + public void ItDoesNotDropDependenciesThatDoNotHaveAMatchingVersionInTheMapping( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + + [Theory] + [InlineData("Microsoft.AspNetCore.Antiforgery", "1.0.0", "Microsoft.AspNetCore.Antiforgery", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc", "1.0.0", "Microsoft.AspNetCore.Mvc", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Abstractions", "1.0.0", "Microsoft.AspNetCore.Mvc.Abstractions", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.ApiExplorer", "1.0.0", "Microsoft.AspNetCore.Mvc.ApiExplorer", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Core", "1.0.0", "Microsoft.AspNetCore.Mvc.Core", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Cors", "1.0.0", "Microsoft.AspNetCore.Mvc.Cors", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.DataAnnotations", "1.0.0", "Microsoft.AspNetCore.Mvc.DataAnnotations", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Formatters.Json", "1.0.0", "Microsoft.AspNetCore.Mvc.Formatters.Json", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Formatters.Xml", "1.0.0", "Microsoft.AspNetCore.Mvc.Formatters.Xml", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Localization", "1.0.0", "Microsoft.AspNetCore.Mvc.Localization", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Razor", "1.0.0", "Microsoft.AspNetCore.Mvc.Razor", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Razor.Host", "1.0.0", "Microsoft.AspNetCore.Mvc.Razor.Host", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.TagHelpers", "1.0.0", "Microsoft.AspNetCore.Mvc.TagHelpers", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.ViewFeatures", "1.0.0", "Microsoft.AspNetCore.Mvc.ViewFeatures", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.WebApiCompatShim", "1.0.0", "Microsoft.AspNetCore.Mvc.WebApiCompatShim", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Routing", "1.0.0", "Microsoft.AspNetCore.Routing", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Routing.Abstractions", "1.0.0", "Microsoft.AspNetCore.Routing.Abstractions", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Server.Kestrel", "1.0.0", "Microsoft.AspNetCore.Server.Kestrel", ConstantPackageVersions.AspNetLTSPackagesVersion)] + [InlineData("Microsoft.AspNetCore.Server.Kestrel.Https", "1.0.0", "Microsoft.AspNetCore.Server.Kestrel.Https", ConstantPackageVersions.AspNetLTSPackagesVersion)] + public void ItUpliftsAspNetCorePackages( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + + [Theory] + [InlineData("Microsoft.EntityFrameworkCore", "1.0.0", "Microsoft.EntityFrameworkCore", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + [InlineData("Microsoft.EntityFrameworkCore.InMemory", "1.0.0", "Microsoft.EntityFrameworkCore.InMemory", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + [InlineData("Microsoft.EntityFrameworkCore.Relational", "1.0.0", "Microsoft.EntityFrameworkCore.Relational", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + [InlineData("Microsoft.EntityFrameworkCore.Relational.Design", "1.0.0", "Microsoft.EntityFrameworkCore.Relational.Design", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + [InlineData("Microsoft.EntityFrameworkCore.Sqlite", "1.0.0", "Microsoft.EntityFrameworkCore.Sqlite", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + [InlineData("Microsoft.EntityFrameworkCore.Sqlite.Design", "1.0.0", "Microsoft.EntityFrameworkCore.Sqlite.Design", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + [InlineData("Microsoft.EntityFrameworkCore.SqlServer", "1.0.0", "Microsoft.EntityFrameworkCore.SqlServer", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + [InlineData("Microsoft.EntityFrameworkCore.SqlServer.Design", "1.0.0", "Microsoft.EntityFrameworkCore.SqlServer.Design", ConstantPackageVersions.EntityFrameworkLTSPackagesVersion)] + public void ItUpliftsEntityFrameworkCorePackages( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + + [Theory] + [InlineData("Microsoft.NETCore.Jit", "1.0.0", "Microsoft.NETCore.Jit", "1.0.5")] + [InlineData("Microsoft.NETCore.Runtime.CoreCLR", "1.0.0", "Microsoft.NETCore.Runtime.CoreCLR", "1.0.5")] + [InlineData("Microsoft.NETCore.DotNetHost", "1.0.0", "Microsoft.NETCore.DotNetHost", "1.0.1")] + [InlineData("Microsoft.NETCore.DotNetHostPolicy", "1.0.0", "Microsoft.NETCore.DotNetHostPolicy", "1.0.3")] + [InlineData("Microsoft.NETCore.DotNetHostResolver", "1.0.0", "Microsoft.NETCore.DotNetHostResolver", "1.0.1")] + [InlineData("Microsoft.NETCore.Platforms", "1.0.0", "Microsoft.NETCore.Platforms", "1.0.2")] + [InlineData("Microsoft.NETCore.Targets", "1.0.0", "Microsoft.NETCore.Targets", "1.0.1")] + [InlineData("Microsoft.NETCore.Windows.ApiSets", "1.0.0", "Microsoft.NETCore.Windows.ApiSets", "1.0.1")] + public void ItUpliftsCoreCLRPackages( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + + [Theory] + [InlineData("System.Net.Http", "1.0.0", "System.Net.Http", "4.1.1")] + [InlineData("System.AppContext", "1.0.0", "System.AppContext", "4.1.0")] + [InlineData("System.Buffers", "1.0.0", "System.Buffers", "4.0.0")] + [InlineData("System.Collections", "1.0.0", "System.Collections", "4.0.11")] + [InlineData("System.Collections.Concurrent", "1.0.0", "System.Collections.Concurrent", "4.0.12")] + [InlineData("System.Collections.Immutable", "1.0.0", "System.Collections.Immutable", "1.2.0")] + [InlineData("System.ComponentModel", "1.0.0", "System.ComponentModel", "4.0.1")] + [InlineData("System.Console", "1.0.0", "System.Console", "4.0.0")] + [InlineData("System.Diagnostics.Debug", "1.0.0", "System.Diagnostics.Debug", "4.0.11")] + [InlineData("System.Diagnostics.DiagnosticSource", "1.0.0", "System.Diagnostics.DiagnosticSource", "4.0.0")] + [InlineData("System.Diagnostics.FileVersionInfo", "1.0.0", "System.Diagnostics.FileVersionInfo", "4.0.0")] + [InlineData("System.Diagnostics.Process", "1.0.0", "System.Diagnostics.Process", "4.1.0")] + [InlineData("System.Diagnostics.StackTrace", "1.0.0", "System.Diagnostics.StackTrace", "4.0.1")] + [InlineData("System.Diagnostics.Tools", "1.0.0", "System.Diagnostics.Tools", "4.0.1")] + [InlineData("System.Diagnostics.Tracing", "1.0.0", "System.Diagnostics.Tracing", "4.1.0")] + [InlineData("System.Dynamic.Runtime", "1.0.0", "System.Dynamic.Runtime", "4.0.11")] + [InlineData("System.Globalization", "1.0.0", "System.Globalization", "4.0.11")] + [InlineData("System.Globalization.Calendars", "1.0.0", "System.Globalization.Calendars", "4.0.1")] + [InlineData("System.Globalization.Extensions", "1.0.0", "System.Globalization.Extensions", "4.0.1")] + [InlineData("System.IO", "1.0.0", "System.IO", "4.1.0")] + [InlineData("System.IO.Compression", "1.0.0", "System.IO.Compression", "4.1.0")] + [InlineData("System.IO.Compression.ZipFile", "1.0.0", "System.IO.Compression.ZipFile", "4.0.1")] + [InlineData("System.IO.MemoryMappedFiles", "1.0.0", "System.IO.MemoryMappedFiles", "4.0.0")] + [InlineData("System.IO.UnmanagedMemoryStream", "1.0.0", "System.IO.UnmanagedMemoryStream", "4.0.1")] + [InlineData("System.Linq", "1.0.0", "System.Linq", "4.1.0")] + [InlineData("System.Linq.Expressions", "1.0.0", "System.Linq.Expressions", "4.1.0")] + [InlineData("System.Linq.Parallel", "1.0.0", "System.Linq.Parallel", "4.0.1")] + [InlineData("System.Linq.Queryable", "1.0.0", "System.Linq.Queryable", "4.0.1")] + [InlineData("System.Net.NameResolution", "1.0.0", "System.Net.NameResolution", "4.0.0")] + [InlineData("System.Net.Primitives", "1.0.0", "System.Net.Primitives", "4.0.11")] + [InlineData("System.Net.Requests", "1.0.0", "System.Net.Requests", "4.0.11")] + [InlineData("System.Net.Security", "1.0.0", "System.Net.Security", "4.0.0")] + [InlineData("System.Net.Sockets", "1.0.0", "System.Net.Sockets", "4.1.0")] + [InlineData("System.Net.WebHeaderCollection", "1.0.0", "System.Net.WebHeaderCollection", "4.0.1")] + [InlineData("System.Numerics.Vectors", "1.0.0", "System.Numerics.Vectors", "4.1.1")] + [InlineData("System.ObjectModel", "1.0.0", "System.ObjectModel", "4.0.12")] + [InlineData("System.Reflection", "1.0.0", "System.Reflection", "4.1.0")] + [InlineData("System.Reflection.DispatchProxy", "1.0.0", "System.Reflection.DispatchProxy", "4.0.1")] + [InlineData("System.Reflection.Emit", "1.0.0", "System.Reflection.Emit", "4.0.1")] + [InlineData("System.Reflection.Emit.ILGeneration", "1.0.0", "System.Reflection.Emit.ILGeneration", "4.0.1")] + [InlineData("System.Reflection.Emit.Lightweight", "1.0.0", "System.Reflection.Emit.Lightweight", "4.0.1")] + [InlineData("System.Reflection.Extensions", "1.0.0", "System.Reflection.Extensions", "4.0.1")] + [InlineData("System.Reflection.Metadata", "1.0.0", "System.Reflection.Metadata", "1.3.0")] + [InlineData("System.Reflection.Primitives", "1.0.0", "System.Reflection.Primitives", "4.0.1")] + [InlineData("System.Reflection.TypeExtensions", "1.0.0", "System.Reflection.TypeExtensions", "4.1.0")] + [InlineData("System.Resources.Reader", "1.0.0", "System.Resources.Reader", "4.0.0")] + [InlineData("System.Resources.ResourceManager", "1.0.0", "System.Resources.ResourceManager", "4.0.1")] + [InlineData("System.Runtime", "1.0.0", "System.Runtime", "4.1.0")] + [InlineData("System.Runtime.Extensions", "1.0.0", "System.Runtime.Extensions", "4.1.0")] + [InlineData("System.Runtime.Handles", "1.0.0", "System.Runtime.Handles", "4.0.1")] + [InlineData("System.Runtime.InteropServices", "1.0.0", "System.Runtime.InteropServices", "4.1.0")] + [InlineData("System.Runtime.InteropServices.RuntimeInformation", "1.0.0", "System.Runtime.InteropServices.RuntimeInformation", "4.0.0")] + [InlineData("System.Runtime.Loader", "1.0.0", "System.Runtime.Loader", "4.0.0")] + [InlineData("System.Runtime.Numerics", "1.0.0", "System.Runtime.Numerics", "4.0.1")] + [InlineData("System.Security.Claims", "1.0.0", "System.Security.Claims", "4.0.1")] + [InlineData("System.Security.Cryptography.Algorithms", "1.0.0", "System.Security.Cryptography.Algorithms", "4.2.0")] + [InlineData("System.Security.Cryptography.Cng", "1.0.0", "System.Security.Cryptography.Cng", "4.2.0")] + [InlineData("System.Security.Cryptography.Csp", "1.0.0", "System.Security.Cryptography.Csp", "4.0.0")] + [InlineData("System.Security.Cryptography.Encoding", "1.0.0", "System.Security.Cryptography.Encoding", "4.0.0")] + [InlineData("System.Security.Cryptography.OpenSsl", "1.0.0", "System.Security.Cryptography.OpenSsl", "4.0.0")] + [InlineData("System.Security.Cryptography.Primitives", "1.0.0", "System.Security.Cryptography.Primitives", "4.0.0")] + [InlineData("System.Security.Cryptography.X509Certificates", "1.0.0", "System.Security.Cryptography.X509Certificates", "4.1.0")] + [InlineData("System.Security.Principal", "1.0.0", "System.Security.Principal", "4.0.1")] + [InlineData("System.Security.Principal.Windows", "1.0.0", "System.Security.Principal.Windows", "4.0.0")] + [InlineData("System.Text.Encoding", "1.0.0", "System.Text.Encoding", "4.0.11")] + [InlineData("System.Text.Encoding.CodePages", "1.0.0", "System.Text.Encoding.CodePages", "4.0.1")] + [InlineData("System.Text.Encoding.Extensions", "1.0.0", "System.Text.Encoding.Extensions", "4.0.11")] + [InlineData("System.Text.RegularExpressions", "1.0.0", "System.Text.RegularExpressions", "4.1.0")] + [InlineData("System.Threading", "1.0.0", "System.Threading", "4.0.11")] + [InlineData("System.Threading.Overlapped", "1.0.0", "System.Threading.Overlapped", "4.0.1")] + [InlineData("System.Threading.Tasks", "1.0.0", "System.Threading.Tasks", "4.0.11")] + [InlineData("System.Threading.Tasks.Dataflow", "1.0.0", "System.Threading.Tasks.Dataflow", "4.6.0")] + [InlineData("System.Threading.Tasks.Extensions", "1.0.0", "System.Threading.Tasks.Extensions", "4.0.0")] + [InlineData("System.Threading.Tasks.Parallel", "1.0.0", "System.Threading.Tasks.Parallel", "4.0.1")] + [InlineData("System.Threading.Thread", "1.0.0", "System.Threading.Thread", "4.0.0")] + [InlineData("System.Threading.ThreadPool", "1.0.0", "System.Threading.ThreadPool", "4.0.10")] + [InlineData("System.Threading.Timer", "1.0.0", "System.Threading.Timer", "4.0.1")] + [InlineData("System.Xml.ReaderWriter", "1.0.0", "System.Xml.ReaderWriter", "4.0.11")] + [InlineData("System.Xml.XDocument", "1.0.0", "System.Xml.XDocument", "4.0.11")] + [InlineData("System.Xml.XmlDocument", "1.0.0", "System.Xml.XmlDocument", "4.0.1")] + [InlineData("System.Xml.XPath", "1.0.0", "System.Xml.XPath", "4.0.1")] + [InlineData("runtime.native.System", "1.0.0", "runtime.native.System", "4.0.0")] + [InlineData("runtime.native.System.IO.Compression", "1.0.0", "runtime.native.System.IO.Compression", "4.1.0")] + [InlineData("runtime.native.System.Net.Http", "1.0.0", "runtime.native.System.Net.Http", "4.0.1")] + [InlineData("runtime.native.System.Net.Security", "1.0.0", "runtime.native.System.Net.Security", "4.0.1")] + [InlineData("runtime.native.System.Security.Cryptography", "1.0.0", "runtime.native.System.Security.Cryptography", "4.0.0")] + [InlineData("Libuv", "1.0.0", "Libuv", "1.9.1")] + [InlineData("Microsoft.CodeAnalysis.Analyzers", "1.0.0", "Microsoft.CodeAnalysis.Analyzers", "1.1.0")] + [InlineData("Microsoft.CodeAnalysis.Common", "1.0.0", "Microsoft.CodeAnalysis.Common", "1.3.0")] + [InlineData("Microsoft.CodeAnalysis.CSharp", "1.0.0", "Microsoft.CodeAnalysis.CSharp", "1.3.0")] + [InlineData("Microsoft.CodeAnalysis.VisualBasic", "1.0.0", "Microsoft.CodeAnalysis.VisualBasic", "1.3.0")] + [InlineData("Microsoft.CSharp", "1.0.0", "Microsoft.CSharp", "4.0.1")] + [InlineData("Microsoft.VisualBasic", "1.0.0", "Microsoft.VisualBasic", "10.0.1")] + [InlineData("Microsoft.Win32.Primitives", "1.0.0", "Microsoft.Win32.Primitives", "4.0.1")] + [InlineData("Microsoft.Win32.Registry", "1.0.0", "Microsoft.Win32.Registry", "4.0.0")] + [InlineData("System.IO.FileSystem", "1.0.0", "System.IO.FileSystem", "4.0.1")] + [InlineData("System.IO.FileSystem.Primitives", "1.0.0", "System.IO.FileSystem.Primitives", "4.0.1")] + [InlineData("System.IO.FileSystem.Watcher", "1.0.0", "System.IO.FileSystem.Watcher", "4.0.0")] + public void ItUpliftsMicrosoftNETCoreAppPackages( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + + [Theory] + [InlineData("Microsoft.Extensions.Logging", "1.0.0", "Microsoft.Extensions.Logging", "1.0.1")] + [InlineData("Microsoft.Extensions.Logging.Console", "1.0.0", "Microsoft.Extensions.Logging.Console", "1.0.1")] + [InlineData("Microsoft.Extensions.Logging.Debug", "1.0.0", "Microsoft.Extensions.Logging.Debug", "1.0.1")] + [InlineData("Microsoft.Extensions.Configuration.Json", "1.0.0", "Microsoft.Extensions.Configuration.Json", "1.0.1")] + [InlineData("Microsoft.Extensions.Configuration.UserSecrets", "1.0.0", "Microsoft.Extensions.Configuration.UserSecrets", "1.0.1")] + public void ItUpliftsMicrosoftExtensionsPackages( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + + private void ValidatePackageMigration( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + var mockProj = RunPackageDependenciesRuleOnPj("{ \"dependencies\": { \"" + sourcePackageName + "\" : { \"version\": \"" + sourceVersion + "\", \"type\": \"build\" } } }"); + + var packageRef = mockProj.Items.First(i => i.Include == targetPackageName && i.ItemType == "PackageReference"); + + packageRef.GetMetadataWithName("Version").Value.Should().Be(targetVersion); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs index a50f785cb..4c70e90c4 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs @@ -130,7 +130,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests // From ProjectReader #L725 (Both are empty) var defaultIncludePatterns = Enumerable.Empty(); - var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns; + var defaultExcludePatterns = Enumerable.Empty(); foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal))) { @@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests // From ProjectReader #L725 (Both are empty) var defaultIncludePatterns = Enumerable.Empty(); - var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns; + var defaultExcludePatterns = Enumerable.Empty(); foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal))) { diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateScripts.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateScripts.cs index 05dcbbcc1..9122551db 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateScripts.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateScripts.cs @@ -63,10 +63,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); + var commands = new string[] { "fakecommand" }; var target = scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, scriptName, IsMultiTFM); @@ -83,10 +86,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); var commands = new[] { "fakecommand" }; var target = scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, scriptName, IsMultiTFM); @@ -103,12 +108,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); var commands = new[] { "fakecommand1", "fakecommand2", "mockcommand3" }; var commandsInTask = commands.ToDictionary(c => c, c => false); var target = scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, scriptName, IsMultiTFM); @@ -140,11 +147,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); var commands = new[] { "%compile:FullTargetFramework%", "%compile:Configuration%"}; var target = scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, scriptName, IsMultiTFM); @@ -167,6 +176,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); var commands = new[] { @@ -175,12 +185,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests var target = scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, "postpublish", IsMultiTFM); target.Tasks.Should().BeEmpty(); } + [Fact] + public void MigratingScriptsReplacesRazorPrecompileWithProperty() + { + var scriptMigrationRule = new MigrateScriptsRule(); + ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); + + var commands = new string[] { "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%" }; + + var target = scriptMigrationRule.MigrateScriptSet( + mockProj, + commonPropertyGroup, + commands, + "postpublish", + IsMultiTFM); + + target.Tasks.Should().BeEmpty(); + commonPropertyGroup.Properties.Count().Should().Be(1); + var propertyElement = commonPropertyGroup.Properties.First(); + propertyElement.Name.Should().Be("MvcRazorCompileOnPublish"); + propertyElement.Value.Should().Be("true"); + } + [Fact] public void FormattingScriptCommandsReplacesUnknownVariablesWithMSBuildPropertyForEnvironmentVariableSupport() { @@ -193,11 +227,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); var commands = new[] { "compile:FullTargetFramework", "compile:Configuration"}; var target = scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, "prepublish", IsMultiTFM); @@ -209,11 +245,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); var commands = new[] { "compile:FullTargetFramework", "compile:Configuration"}; var target = scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, "prepublish", false); @@ -225,11 +263,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var scriptMigrationRule = new MigrateScriptsRule(); ProjectRootElement mockProj = ProjectRootElement.Create(); + ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup(); var commands = new string[] { "fakecommand" }; Action action = () => scriptMigrationRule.MigrateScriptSet( mockProj, + commonPropertyGroup, commands, "invalidScriptSet", IsMultiTFM); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs index f6658bbf0..683621ffa 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTFMs.cs @@ -73,7 +73,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var testDirectory = Temp.CreateDirectory().Path; var testPJ = new ProjectJsonBuilder(TestAssetsManager) - .FromTestAssetBase("TestLibraryWithMultipleFrameworks") + .FromTestAssetBase("PJAppWithMultipleFrameworks") .SaveToDisk(testDirectory); var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory); @@ -98,7 +98,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { var testDirectory = Temp.CreateDirectory().Path; var testPJ = new ProjectJsonBuilder(TestAssetsManager) - .FromTestAssetBase("TestLibraryWithMultipleFrameworks") + .FromTestAssetBase("PJAppWithMultipleFrameworks") .SaveToDisk(testDirectory); var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory); @@ -197,5 +197,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests mockProj.Properties.Count(p => p.Name == "TargetFramework").Should().Be(1); } + + [Fact] + public void MigratingLibWithMultipleTFMsDoesNotAddRuntimes() + { + var testDirectory = Temp.CreateDirectory().Path; + var testPJ = new ProjectJsonBuilder(TestAssetsManager) + .FromTestAssetBase("PJLibWithMultipleFrameworks") + .SaveToDisk(testDirectory); + + var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory); + var mockProj = ProjectRootElement.Create(); + + var migrationSettings = + MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj); + var migrationInputs = new MigrationRuleInputs( + projectContexts, + mockProj, + mockProj.AddItemGroup(), + mockProj.AddPropertyGroup()); + + new MigrateTFMRule().Apply(migrationSettings, migrationInputs); + + var reason = "Should not add runtime identifiers for libraries"; + mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0, reason); + mockProj.Properties.Count(p => p.Name == "RuntimeIdentifier").Should().Be(0, reason); + } } } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTools.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTools.cs index 27ed9fb96..a014ac163 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTools.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateTools.cs @@ -12,19 +12,24 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests public class GivenThatIWantToMigrateTools : PackageDependenciesTestBase { [Theory] - [InlineData("Microsoft.EntityFrameworkCore.Tools", "Microsoft.EntityFrameworkCore.Tools", ConstantPackageVersions.AspNetToolsVersion)] - [InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNetToolsVersion)] - public void It_migrates_project_dependencies_to_a_new_name_and_version( + [InlineData("Microsoft.EntityFrameworkCore.Tools", "1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Tools", ConstantPackageVersions.AspNetToolsVersion)] + [InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.0.0-preview2-final", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNetToolsVersion)] + [InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.0.0-*", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNetToolsVersion)] + [InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.0.1", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNetToolsVersion)] + [InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.0.0-preview3-final", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNetToolsVersion)] + [InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.1.0-preview4-final", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNet110ToolsVersion)] + [InlineData("Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design", "1.1.0-preview4-final", "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation", ConstantPackageVersions.AspNet110ToolsVersion)] + public void ItMigratesProjectDependenciesToANewNameAndVersion( string sourceToolName, + string sourceVersion, string targetToolName, string targetVersion) { - const string anyVersion = "1.0.0-preview2-final"; - var mockProj = RunPackageDependenciesRuleOnPj("{ \"dependencies\": { \"" + sourceToolName + "\" : { \"version\": \"" + anyVersion + "\", \"type\": \"build\" } } }"); + var mockProj = RunPackageDependenciesRuleOnPj("{ \"dependencies\": { \"" + sourceToolName + "\" : { \"version\": \"" + sourceVersion + "\", \"type\": \"build\" } } }"); var packageRef = mockProj.Items.First(i => i.Include == targetToolName && i.ItemType == "PackageReference"); - packageRef.GetMetadataWithName("Version").Value.Should().Be(ConstantPackageVersions.AspNetToolsVersion); + packageRef.GetMetadataWithName("Version").Value.Should().Be(targetVersion); packageRef.GetMetadataWithName("PrivateAssets").Value.Should().NotBeNull().And.Be("All"); } @@ -35,7 +40,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests [InlineData("Microsoft.VisualStudio.Web.CodeGeneration.Tools")] [InlineData("dotnet-test-xunit")] [InlineData("dotnet-test-mstest")] - public void It_does_not_migrate_project_tool_dependency_that_is_no_longer_needed(string dependencyName) + public void ItDoesNotMigrateProjectToolDependencyThatIsNoLongerNeeded(string dependencyName) { var mockProj = RunPackageDependenciesRuleOnPj(@" { @@ -59,7 +64,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests [InlineData("Microsoft.DotNet.Watcher.Tools", "Microsoft.DotNet.Watcher.Tools", ConstantPackageVersions.AspNetToolsVersion)] [InlineData("Microsoft.Extensions.SecretManager.Tools", "Microsoft.Extensions.SecretManager.Tools", ConstantPackageVersions.AspNetToolsVersion)] [InlineData("BundlerMinifier.Core", "BundlerMinifier.Core", ConstantPackageVersions.BundleMinifierToolVersion)] - public void It_migrates_asp_project_tools_to_a_new_name_and_version( + public void ItMigratesAspProjectToolsToANewNameAndVersion( string sourceToolName, string targetToolName, string targetVersion) @@ -73,7 +78,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests [Theory] [InlineData("Microsoft.AspNetCore.Razor.Tools")] [InlineData("Microsoft.AspNetCore.Server.IISIntegration.Tools")] - public void It_does_not_migrate_asp_project_tool(string toolName) + [InlineData("Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools")] + public void ItDoesNotMigrateAspProjectTool(string toolName) { var mockProj = RunPackageDependenciesRuleOnPj(@" { diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index 6621200c7..2e511c1b3 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -202,6 +202,26 @@ namespace Microsoft.DotNet.Migration.Tests outputsIdentical.Should().BeTrue(); } + [WindowsOnlyFact] + public void ItMigratesLibraryWithMultipleTFMsAndFullFramework() + { + var projectName = "PJLibWithMultipleFrameworks"; + var projectDirectory = + TestAssetsManager.CreateTestInstance(projectName, identifier: projectName).WithLockFiles().Path; + + var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName); + + var outputsIdentical = + outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs); + + if (!outputsIdentical) + { + OutputDiagnostics(outputComparisonData); + } + + outputsIdentical.Should().BeTrue(); + } + [Theory] [InlineData("TestAppWithLibrary/TestLibrary")] [InlineData("TestLibraryWithAnalyzer")]