From c2f60cede402e7e56093de89c4e3bb3f47b34e4d Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Fri, 28 Oct 2016 17:59:14 -0700 Subject: [PATCH 01/11] Updating the SDK to the latest. --- TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj | 2 +- TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj | 2 +- .../TestProjectWithUnresolvedPlatformDependency.csproj | 2 +- .../AppWithDepOnToolWithOutputName.csproj | 2 +- .../AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj | 2 +- .../TestProjects/AppWithDirectDep/AppWithDirectDep.csproj | 2 +- .../AppWithDirectDepWithOutputName.csproj | 2 +- .../MSBuildAppWithMultipleFrameworksAndTools.csproj | 2 +- .../AppWithToolDependency/AppWithToolDependency.csproj | 2 +- .../DependencyContextFromTool.csproj | 2 +- .../LibraryWithOutputAssemblyName/MyLibrary.csproj | 2 +- .../MSBuildAppWithMultipleFrameworks.csproj | 2 +- .../MSBuildAppWithMultipleFrameworksAndTools.csproj | 2 +- TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj | 2 +- .../CsprojLibrary1/CsprojLibrary1.csproj | 2 +- .../TestAppDependencyGraph/CsprojLibrary1/project.json | 2 +- .../CsprojLibrary2/CsprojLibrary2.csproj | 2 +- .../TestAppDependencyGraph/CsprojLibrary2/project.json | 2 +- .../CsprojLibrary3/CsprojLibrary3.csproj | 2 +- .../TestAppDependencyGraph/CsprojLibrary3/project.json | 2 +- TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj | 2 +- .../TestAppWithProjDepTool/TestAppWithProjDepTool.csproj | 2 +- .../TestLibraryWithConfiguration.csproj | 2 +- .../VSTestDotNetCoreProject/VSTestDotNetCoreProject.csproj | 2 +- build_projects/dotnet-cli-build/dotnet-cli-build.csproj | 5 +---- .../commands/dotnet-new/CSharp_Console/$projectName$.csproj | 2 +- .../commands/dotnet-new/CSharp_Lib/$projectName$.csproj | 2 +- .../commands/dotnet-new/CSharp_Web/$projectName$.csproj | 2 +- 28 files changed, 28 insertions(+), 31 deletions(-) diff --git a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj index 110929efb..fbf82b1d1 100644 --- a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj +++ b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj @@ -13,7 +13,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj b/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj index cecdf152a..a20781af5 100644 --- a/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj +++ b/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj @@ -13,7 +13,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedPlatformDependency/TestProjectWithUnresolvedPlatformDependency.csproj b/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedPlatformDependency/TestProjectWithUnresolvedPlatformDependency.csproj index 0983f08f8..753ce3b5a 100755 --- a/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedPlatformDependency/TestProjectWithUnresolvedPlatformDependency.csproj +++ b/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedPlatformDependency/TestProjectWithUnresolvedPlatformDependency.csproj @@ -13,7 +13,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj b/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj index 0c47bdf3f..43f7a3f89 100755 --- a/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj +++ b/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj @@ -12,7 +12,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj b/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj index f37b2dba6..28d0d536b 100755 --- a/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj +++ b/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj @@ -12,7 +12,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj b/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj index 87e79722c..d56778ff1 100755 --- a/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj +++ b/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj @@ -21,7 +21,7 @@ - 1.0.0-alpha-20161012-3 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj b/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj index a1803c769..3dfa82c90 100755 --- a/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj +++ b/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj @@ -12,7 +12,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj b/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj index a7fad9b20..5dc85d343 100644 --- a/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj +++ b/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj @@ -9,7 +9,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj b/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj index 28f991567..721b9712e 100755 --- a/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj +++ b/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj @@ -12,7 +12,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj b/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj index 7b91a326c..b6e9522d6 100755 --- a/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj +++ b/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj @@ -14,7 +14,7 @@ - 1.0.0-alpha-20161012-3 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/LibraryWithOutputAssemblyName/MyLibrary.csproj b/TestAssets/TestProjects/LibraryWithOutputAssemblyName/MyLibrary.csproj index f32fd4d2e..871825f1c 100755 --- a/TestAssets/TestProjects/LibraryWithOutputAssemblyName/MyLibrary.csproj +++ b/TestAssets/TestProjects/LibraryWithOutputAssemblyName/MyLibrary.csproj @@ -11,7 +11,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj index e7842b636..a8887e874 100644 --- a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj +++ b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj @@ -9,7 +9,7 @@ - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj index 0f8b4a535..5dc85d343 100644 --- a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj +++ b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj @@ -9,7 +9,7 @@ - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj index ec55505c2..5d222791c 100644 --- a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj +++ b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj @@ -16,7 +16,7 @@ 1.0.1 - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj index 4cf4c469a..556860038 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/CsprojLibrary1.csproj @@ -14,7 +14,7 @@ - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/project.json b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/project.json index ea1b66242..20613dfc1 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/project.json +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary1/project.json @@ -3,7 +3,7 @@ "frameworks": { "netstandard1.5": { "dependencies": { - "Microsoft.NET.Sdk": "1.0.0-alpha-20161026-2", + "Microsoft.NET.Sdk": "1.0.0-alpha-20161029-1", "NETStandard.Library": "1.6.0" } } diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj index 4cf4c469a..556860038 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/CsprojLibrary2.csproj @@ -14,7 +14,7 @@ - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/project.json b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/project.json index ea1b66242..20613dfc1 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/project.json +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary2/project.json @@ -3,7 +3,7 @@ "frameworks": { "netstandard1.5": { "dependencies": { - "Microsoft.NET.Sdk": "1.0.0-alpha-20161026-2", + "Microsoft.NET.Sdk": "1.0.0-alpha-20161029-1", "NETStandard.Library": "1.6.0" } } diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj index 4cf4c469a..556860038 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/CsprojLibrary3.csproj @@ -14,7 +14,7 @@ - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/project.json b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/project.json index ea1b66242..20613dfc1 100644 --- a/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/project.json +++ b/TestAssets/TestProjects/TestAppDependencyGraph/CsprojLibrary3/project.json @@ -3,7 +3,7 @@ "frameworks": { "netstandard1.5": { "dependencies": { - "Microsoft.NET.Sdk": "1.0.0-alpha-20161026-2", + "Microsoft.NET.Sdk": "1.0.0-alpha-20161029-1", "NETStandard.Library": "1.6.0" } } diff --git a/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj b/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj index 9fa2cfbb5..dc34e6004 100755 --- a/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj +++ b/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj @@ -12,7 +12,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj b/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj index 3be88edba..8a056988a 100644 --- a/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj +++ b/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj @@ -15,7 +15,7 @@ 1.0.1 - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/TestLibraryWithConfiguration/TestLibraryWithConfiguration.csproj b/TestAssets/TestProjects/TestLibraryWithConfiguration/TestLibraryWithConfiguration.csproj index c69ce99dd..3e748a942 100755 --- a/TestAssets/TestProjects/TestLibraryWithConfiguration/TestLibraryWithConfiguration.csproj +++ b/TestAssets/TestProjects/TestLibraryWithConfiguration/TestLibraryWithConfiguration.csproj @@ -14,7 +14,7 @@ - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 All diff --git a/TestAssets/TestProjects/VSTestDotNetCoreProject/VSTestDotNetCoreProject.csproj b/TestAssets/TestProjects/VSTestDotNetCoreProject/VSTestDotNetCoreProject.csproj index d0246131e..e55de3925 100644 --- a/TestAssets/TestProjects/VSTestDotNetCoreProject/VSTestDotNetCoreProject.csproj +++ b/TestAssets/TestProjects/VSTestDotNetCoreProject/VSTestDotNetCoreProject.csproj @@ -16,7 +16,7 @@ 1.0.1 - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/build_projects/dotnet-cli-build/dotnet-cli-build.csproj b/build_projects/dotnet-cli-build/dotnet-cli-build.csproj index 258b0185a..d97aa8238 100644 --- a/build_projects/dotnet-cli-build/dotnet-cli-build.csproj +++ b/build_projects/dotnet-cli-build/dotnet-cli-build.csproj @@ -43,7 +43,7 @@ 1.0.1-beta-000933 - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All @@ -51,8 +51,5 @@ - - $(DefineConstants);NETCOREAPP1_0 - \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj index 74fb291e9..c82874b90 100755 --- a/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_Console/$projectName$.csproj @@ -16,7 +16,7 @@ 1.0.1 - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj index 296cb5b67..a8c6f3bbb 100755 --- a/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_Lib/$projectName$.csproj @@ -15,7 +15,7 @@ 1.6 - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/src/dotnet/commands/dotnet-new/CSharp_Web/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_Web/$projectName$.csproj index 56dfdae11..1b7f27442 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_Web/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_Web/$projectName$.csproj @@ -17,7 +17,7 @@ 1.0.1 - 1.0.0-alpha-20161019-1 + 1.0.0-alpha-20161029-1 1.0.0 From 9139c4006b508095a60a468d6b86b3e18de547d1 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Mon, 31 Oct 2016 16:22:10 -0700 Subject: [PATCH 02/11] Fixing full framework tests --- .../AppWithProjTool2Fx/App.csproj | 1 + .../project.json | 13 ++++++ .../NuGet.template.config | 6 +++ .../TestAssetInstance.cs | 23 ++++++++++ .../project.json | 7 +++- src/dotnet/commands/dotnet-build/Program.cs | 8 ++++ .../CSharp_xunittest/$projectName$.csproj | 2 +- ...GivenAProjectDependenciesCommandFactory.cs | 42 ++++++++++++++++--- .../Commands/RestoreCommand.cs | 23 +++++++++- .../GivenThatIWantToMigrateTestApps.cs | 17 +++++--- 10 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 src/Microsoft.DotNet.TestFramework/NuGet.template.config diff --git a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj index fbf82b1d1..f3d14e2f3 100644 --- a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj +++ b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj @@ -5,6 +5,7 @@ netcoreapp1.0;net451 Exe $(PackageTargetFallback);portable-net45+win8;dnxcore50 + win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.23-x64;opensuse.13.2-x64 diff --git a/TestAssets/DesktopTestProjects/AutoAddDesktopReferencesDuringMigrate/project.json b/TestAssets/DesktopTestProjects/AutoAddDesktopReferencesDuringMigrate/project.json index a7dea7e1d..1720635d6 100644 --- a/TestAssets/DesktopTestProjects/AutoAddDesktopReferencesDuringMigrate/project.json +++ b/TestAssets/DesktopTestProjects/AutoAddDesktopReferencesDuringMigrate/project.json @@ -7,5 +7,18 @@ "dependencies": {}, "frameworks": { "net451": {} + }, + "runtimes": { + "win7-x64": {}, + "win7-x86": {}, + "osx.10.10-x64": {}, + "osx.10.11-x64": {}, + "ubuntu.14.04-x64": {}, + "ubuntu.16.04-x64": {}, + "centos.7-x64": {}, + "rhel.7.2-x64": {}, + "debian.8-x64": {}, + "fedora.23-x64": {}, + "opensuse.13.2-x64": {} } } diff --git a/src/Microsoft.DotNet.TestFramework/NuGet.template.config b/src/Microsoft.DotNet.TestFramework/NuGet.template.config new file mode 100644 index 000000000..d56457a40 --- /dev/null +++ b/src/Microsoft.DotNet.TestFramework/NuGet.template.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs b/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs index 12c6c27d2..7a88b71be 100644 --- a/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs +++ b/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs @@ -5,7 +5,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.CompilerServices; +using System.Text; using System.Threading.Tasks; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Common; @@ -67,6 +69,27 @@ namespace Microsoft.DotNet.TestFramework return this; } + public TestAssetInstance WithNuGetConfig(string nugetCache) + { + var thisAssembly = typeof(TestAssetInstance).GetTypeInfo().Assembly; + var newNuGetConfigPath = Path.Combine(Root.FullName, "NuGet.config"); + + using (var resource = thisAssembly.GetManifestResourceStream("NuGet.template.config")) + { + var streamReader = new StreamReader(resource); + var content = streamReader.ReadToEnd(); + content = content.Replace("$fullpath$", nugetCache); + + using (var newNuGetConfig = new FileStream(newNuGetConfigPath, FileMode.Create, FileAccess.Write)) + { + var contentBytes = new UTF8Encoding(true).GetBytes(content); + newNuGetConfig.Write(contentBytes, 0, contentBytes.Length); + } + } + + return this; + } + private void CopyFiles(IEnumerable filesToCopy) { foreach (var file in filesToCopy) diff --git a/src/Microsoft.DotNet.TestFramework/project.json b/src/Microsoft.DotNet.TestFramework/project.json index d2fc22f88..0592f9cbd 100644 --- a/src/Microsoft.DotNet.TestFramework/project.json +++ b/src/Microsoft.DotNet.TestFramework/project.json @@ -2,7 +2,12 @@ "version": "1.0.0-preview3-*", "description": "Microsoft.DotNet.TestFramework Class Library", "buildOptions": { - "keyFile": "../../tools/Key.snk" + "keyFile": "../../tools/Key.snk", + "embed": { + "include": [ + "NuGet.template.config" + ] + } }, "dependencies": { "Microsoft.DotNet.Cli.Utils": { diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/Program.cs index d5251a19f..3d0a3f060 100644 --- a/src/dotnet/commands/dotnet-build/Program.cs +++ b/src/dotnet/commands/dotnet-build/Program.cs @@ -28,6 +28,9 @@ namespace Microsoft.DotNet.Tools.Build CommandOption outputOption = app.Option("-o|--output ", "Directory in which to place outputs", CommandOptionType.SingleValue); CommandOption frameworkOption = app.Option("-f|--framework ", "Compile a specific framework", CommandOptionType.SingleValue); + CommandOption runtimeOption = app.Option( + "-r|--runtime ", "Target runtime to build for. The default is to build a portable application.", + CommandOptionType.SingleValue); CommandOption configurationOption = app.Option("-c|--configuration ", "Configuration under which to build", CommandOptionType.SingleValue); CommandOption versionSuffixOption = app.Option("--version-suffix ", "Defines the value for the $(VersionSuffix) property in the project", CommandOptionType.SingleValue); @@ -62,6 +65,11 @@ namespace Microsoft.DotNet.Tools.Build msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); } + if (runtimeOption.HasValue()) + { + msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}"); + } + if (configurationOption.HasValue()) { msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); diff --git a/src/dotnet/commands/dotnet-new/CSharp_xunittest/$projectName$.csproj b/src/dotnet/commands/dotnet-new/CSharp_xunittest/$projectName$.csproj index de3f57990..8884e6a87 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_xunittest/$projectName$.csproj +++ b/src/dotnet/commands/dotnet-new/CSharp_xunittest/$projectName$.csproj @@ -16,7 +16,7 @@ 1.0.1 - 1.0.0-alpha-20161026-2 + 1.0.0-alpha-20161029-1 All diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs index 5ea3a457d..624936a84 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs @@ -29,16 +29,24 @@ namespace Microsoft.DotNet.Cli.Utils.Tests [WindowsOnlyFact] public void It_resolves_desktop_apps_defaulting_to_Debug_Configuration() { + var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var configuration = "Debug"; var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx") .CreateInstance() .WithSourceFiles() - .WithRestoreFiles(); + .WithNuGetConfig(_repoDirectoriesProvider.TestPackages); + + var restoreCommand = new RestoreCommand() + .WithWorkingDirectory(testInstance.Root) + .WithRuntime(runtime) + .ExecuteWithCapturedOutput() + .Should().Pass(); var buildCommand = new BuildCommand() .WithWorkingDirectory(testInstance.Root) .WithConfiguration(configuration) + .WithRuntime(runtime) .WithCapturedOutput() .Execute() .Should().Pass(); @@ -60,16 +68,24 @@ namespace Microsoft.DotNet.Cli.Utils.Tests [WindowsOnlyFact] public void It_resolves_desktop_apps_when_configuration_is_Debug() { + var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var configuration = "Debug"; var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx") .CreateInstance() .WithSourceFiles() - .WithRestoreFiles(); + .WithNuGetConfig(_repoDirectoriesProvider.TestPackages); + + var restoreCommand = new RestoreCommand() + .WithWorkingDirectory(testInstance.Root) + .WithRuntime(runtime) + .ExecuteWithCapturedOutput() + .Should().Pass(); var buildCommand = new BuildCommand() .WithWorkingDirectory(testInstance.Root) .WithConfiguration(configuration) + .WithRuntime(runtime) .Execute() .Should().Pass(); @@ -89,12 +105,19 @@ namespace Microsoft.DotNet.Cli.Utils.Tests [WindowsOnlyFact] public void It_resolves_desktop_apps_when_configuration_is_Release() { - var configuration = "Release"; + var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); + var configuration = "Debug"; var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx") .CreateInstance() .WithSourceFiles() - .WithRestoreFiles(); + .WithNuGetConfig(_repoDirectoriesProvider.TestPackages); + + var restoreCommand = new RestoreCommand() + .WithWorkingDirectory(testInstance.Root) + .WithRuntime(runtime) + .ExecuteWithCapturedOutput() + .Should().Pass(); var buildCommand = new BuildCommand() .WithWorkingDirectory(testInstance.Root) @@ -120,12 +143,19 @@ namespace Microsoft.DotNet.Cli.Utils.Tests [WindowsOnlyFact] public void It_resolves_desktop_apps_using_configuration_passed_to_create() { - var configuration = "Release"; + var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); + var configuration = "Debug"; var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx") .CreateInstance() .WithSourceFiles() - .WithRestoreFiles(); + .WithNuGetConfig(_repoDirectoriesProvider.TestPackages); + + var restoreCommand = new RestoreCommand() + .WithWorkingDirectory(testInstance.Root) + .WithRuntime(runtime) + .ExecuteWithCapturedOutput() + .Should().Pass(); var buildCommand = new BuildCommand() .WithWorkingDirectory(testInstance.Root) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs index a259dcc78..c0096101f 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs @@ -7,21 +7,40 @@ namespace Microsoft.DotNet.Tools.Test.Utilities { public sealed class RestoreCommand : TestCommand { + private string _runtime; + public RestoreCommand() : base("dotnet") { } + public RestoreCommand WithRuntime(string runtime) + { + _runtime = runtime; + + return this; + } + public override CommandResult Execute(string args = "") { - args = $"restore {args} --disable-parallel"; + args = $"restore {GetRuntime()} {args} --disable-parallel"; return base.Execute(args); } public override CommandResult ExecuteWithCapturedOutput(string args = "") { - args = $"restore {args} --disable-parallel"; + args = $"restore {GetRuntime()} {args} --disable-parallel"; return base.ExecuteWithCapturedOutput(args); } + + private string GetRuntime() + { + if (_runtime == null) + { + return null; + } + + return $"/p:RuntimeIdentifier={_runtime}"; + } } } diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index c240aa6ea..a411de556 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -371,13 +371,14 @@ namespace Microsoft.DotNet.Migration.Tests [InlineData("TestProjects", "PJTestAppSimple", false)] public void It_auto_add_desktop_references_during_migrate(string testGroup, string projectName, bool isDesktopApp) { + var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var testAssetManager = GetTestGroupTestAssetsManager(testGroup); var projectDirectory = testAssetManager.CreateTestInstance(projectName).WithLockFiles().Path; CleanBinObj(projectDirectory); MigrateProject(new string[] { projectDirectory }); - Restore(projectDirectory); - BuildMSBuild(projectDirectory, projectName); + Restore(projectDirectory, runtime: runtime); + BuildMSBuild(projectDirectory, projectName, runtime:runtime); VerifyAutoInjectedDesktopReferences(projectDirectory, projectName, isDesktopApp); VerifyAllMSBuildOutputsRunnable(projectDirectory); } @@ -584,10 +585,11 @@ namespace Microsoft.DotNet.Migration.Tests .Should().Pass(); } - private void Restore(string projectDirectory, string projectName=null) + private void Restore(string projectDirectory, string projectName=null, string runtime=null) { var command = new RestoreCommand() - .WithWorkingDirectory(projectDirectory); + .WithWorkingDirectory(projectDirectory) + .WithRuntime(runtime); if (projectName != null) { @@ -601,7 +603,11 @@ namespace Microsoft.DotNet.Migration.Tests } } - private string BuildMSBuild(string projectDirectory, string projectName, string configuration="Debug") + private string BuildMSBuild( + string projectDirectory, + string projectName, + string configuration="Debug", + string runtime=null) { if (projectName != null) { @@ -612,6 +618,7 @@ namespace Microsoft.DotNet.Migration.Tests var result = new BuildCommand() .WithWorkingDirectory(projectDirectory) + .WithRuntime(runtime) .ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}"); result From a95ddb407448fd6797ce6b30214f304285aeaae9 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 1 Nov 2016 00:49:03 -0700 Subject: [PATCH 03/11] Addressing code review comments. --- src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs b/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs index 7a88b71be..c7cda7090 100644 --- a/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs +++ b/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs @@ -72,7 +72,7 @@ namespace Microsoft.DotNet.TestFramework public TestAssetInstance WithNuGetConfig(string nugetCache) { var thisAssembly = typeof(TestAssetInstance).GetTypeInfo().Assembly; - var newNuGetConfigPath = Path.Combine(Root.FullName, "NuGet.config"); + var newNuGetConfig = Root.GetFile("Nuget.config"); using (var resource = thisAssembly.GetManifestResourceStream("NuGet.template.config")) { @@ -80,10 +80,11 @@ namespace Microsoft.DotNet.TestFramework var content = streamReader.ReadToEnd(); content = content.Replace("$fullpath$", nugetCache); - using (var newNuGetConfig = new FileStream(newNuGetConfigPath, FileMode.Create, FileAccess.Write)) + using (var newNuGetConfigStream = + new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write)) { var contentBytes = new UTF8Encoding(true).GetBytes(content); - newNuGetConfig.Write(contentBytes, 0, contentBytes.Length); + newNuGetConfigStream.Write(contentBytes, 0, contentBytes.Length); } } From c7858afc48e36ec6f264e1981fd7d384667ce59b Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 1 Nov 2016 12:46:29 -0700 Subject: [PATCH 04/11] Attempting to actually fix the build this time. We were not pointing to the right packages cache before. --- .../NuGet.template.config | 6 ----- .../TestAssetInstance.cs | 23 ++++++++++--------- .../project.json | 7 +----- ...GivenAProjectDependenciesCommandFactory.cs | 2 ++ .../RepoDirectoriesProvider.cs | 2 +- 5 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 src/Microsoft.DotNet.TestFramework/NuGet.template.config diff --git a/src/Microsoft.DotNet.TestFramework/NuGet.template.config b/src/Microsoft.DotNet.TestFramework/NuGet.template.config deleted file mode 100644 index d56457a40..000000000 --- a/src/Microsoft.DotNet.TestFramework/NuGet.template.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs b/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs index c7cda7090..b8edd694c 100644 --- a/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs +++ b/src/Microsoft.DotNet.TestFramework/TestAssetInstance.cs @@ -74,18 +74,19 @@ namespace Microsoft.DotNet.TestFramework var thisAssembly = typeof(TestAssetInstance).GetTypeInfo().Assembly; var newNuGetConfig = Root.GetFile("Nuget.config"); - using (var resource = thisAssembly.GetManifestResourceStream("NuGet.template.config")) + var content = @" + + + + + "; + content = content.Replace("$fullpath$", nugetCache); + + using (var newNuGetConfigStream = + new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write)) { - var streamReader = new StreamReader(resource); - var content = streamReader.ReadToEnd(); - content = content.Replace("$fullpath$", nugetCache); - - using (var newNuGetConfigStream = - new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write)) - { - var contentBytes = new UTF8Encoding(true).GetBytes(content); - newNuGetConfigStream.Write(contentBytes, 0, contentBytes.Length); - } + var contentBytes = new UTF8Encoding(true).GetBytes(content); + newNuGetConfigStream.Write(contentBytes, 0, contentBytes.Length); } return this; diff --git a/src/Microsoft.DotNet.TestFramework/project.json b/src/Microsoft.DotNet.TestFramework/project.json index 0592f9cbd..d2fc22f88 100644 --- a/src/Microsoft.DotNet.TestFramework/project.json +++ b/src/Microsoft.DotNet.TestFramework/project.json @@ -2,12 +2,7 @@ "version": "1.0.0-preview3-*", "description": "Microsoft.DotNet.TestFramework Class Library", "buildOptions": { - "keyFile": "../../tools/Key.snk", - "embed": { - "include": [ - "NuGet.template.config" - ] - } + "keyFile": "../../tools/Key.snk" }, "dependencies": { "Microsoft.DotNet.Cli.Utils": { diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs index 624936a84..444d04a66 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs @@ -122,6 +122,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var buildCommand = new BuildCommand() .WithWorkingDirectory(testInstance.Root) .WithConfiguration(configuration) + .WithRuntime(runtime) .WithCapturedOutput() .Execute() .Should().Pass(); @@ -160,6 +161,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var buildCommand = new BuildCommand() .WithWorkingDirectory(testInstance.Root) .WithConfiguration(configuration) + .WithRuntime(runtime) .WithCapturedOutput() .Execute() .Should().Pass(); diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs index 356b2234c..c8ad0e772 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs @@ -68,7 +68,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities _nugetPackages = nugetPackages ?? Path.Combine(RepoRoot, ".nuget", "packages"); _pjDotnet = pjDotnet ?? GetPjDotnetPath(); _stage2Sdk = Directory.EnumerateDirectories(Path.Combine(_artifacts, "stage2", "sdk")).First(); - _testPackages = Path.Combine(_artifacts, "tests", "packages"); + _testPackages = Path.Combine(RepoRoot, "artifacts", "testpackages", "packages"); } private string GetPjDotnetPath() From 82ff6397f5d3bf58bd59e133346b9be768852348 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 1 Nov 2016 14:11:11 -0700 Subject: [PATCH 05/11] Migrating unqualifing references as projects if we find a matching project. Without this, we have project references being migrated as package references. --- .../ProjectA/.noautobuild | 0 .../ProjectA/Program.cs | 19 ++++++++++++ .../ProjectA/project.json | 27 ++++++++++++++++ .../ProjectB/.noautobuild | 0 .../ProjectB/Helper.cs | 15 +++++++++ .../ProjectB/project.json | 18 +++++++++++ .../ProjectDependencyFinder.cs | 3 +- ...enThatIWantToMigrateProjectDependencies.cs | 31 +++++++++++++++---- 8 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/.noautobuild create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/.noautobuild create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs create mode 100644 TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/.noautobuild b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs new file mode 100644 index 000000000..9576b17c4 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/Program.cs @@ -0,0 +1,19 @@ +// 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.Diagnostics; +using TestLibrary; + +namespace TestApp +{ + public class Program + { + public static int Main(string[] args) + { + Console.WriteLine("This string came from ProjectA"); + Console.WriteLine($"{ProjectB.GetMessage()}"); + return 0; + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json new file mode 100644 index 000000000..5287abb9b --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectA/project.json @@ -0,0 +1,27 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true, + "preserveCompilationContext": true + }, + "dependencies": { + "ProjectB": "1.0.0-*", + "Microsoft.NETCore.App": "1.0.1" + }, + "frameworks": { + "netcoreapp1.0": {} + }, + "runtimes": { + "win7-x64": {}, + "win7-x86": {}, + "osx.10.10-x64": {}, + "osx.10.11-x64": {}, + "ubuntu.14.04-x64": {}, + "ubuntu.16.04-x64": {}, + "centos.7-x64": {}, + "rhel.7.2-x64": {}, + "debian.8-x64": {}, + "fedora.23-x64": {}, + "opensuse.13.2-x64": {} + } +} diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/.noautobuild b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs new file mode 100644 index 000000000..5a986d891 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/Helper.cs @@ -0,0 +1,15 @@ +// 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; + +namespace TestLibrary +{ + public static class ProjectB + { + public static string GetMessage() + { + return "This string came from ProjectB"; + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json new file mode 100644 index 000000000..48bc772d8 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithUnqualifiedDependencies/ProjectB/project.json @@ -0,0 +1,18 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "nowarn": [ + "CS1591" + ], + "xmlDoc": true, + "additionalArguments": [ + "-highentropyva+" + ] + }, + "dependencies": { + "NETStandard.Library": "1.6.0" + }, + "frameworks": { + "netstandard1.5": {} + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs index b82adcd2f..ab69f6cc0 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs @@ -98,7 +98,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration foreach (var projectFileDependency in projectFileDependenciesForFramework.Where(p => - p.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project)) + p.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project || + p.LibraryRange.TypeConstraint == LibraryDependencyTarget.All)) { var dependencyName = projectFileDependency.Name; diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs index 346d35434..13648ef0e 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs @@ -242,10 +242,28 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests [Fact] public void It_promotes_P2P_references_up_in_the_dependency_chain() { - var solutionDirectory = - TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: "p").Path; + var mockProj = MigrateProject("TestAppDependencyGraph", "ProjectA"); - var appDirectory = Path.Combine(solutionDirectory, "ProjectA"); + var projectReferences = mockProj.Items.Where( + item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal)); + projectReferences.Count().Should().Be(7); + } + + [Fact] + public void It_migrates_unqualified_dependencies_as_ProjectReference_when_a_matching_project_is_found() + { + var mockProj = MigrateProject("TestAppWithUnqualifiedDependencies", "ProjectA"); + + var projectReferences = mockProj.Items.Should().ContainSingle( + item => item.ItemType == "ProjectReference" && item.Include == "../ProjectB/ProjectB.csproj"); + } + + private ProjectRootElement MigrateProject(string solution, string project) + { + var solutionDirectory = + TestAssetsManager.CreateTestInstance(solution, callingMethod: "p").Path; + + var appDirectory = Path.Combine(solutionDirectory, project); var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var mockProj = ProjectRootElement.Create(); @@ -254,9 +272,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests mockProj.AddPropertyGroup()); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); - var projectReferences = mockProj.Items.Where( - item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal)); - projectReferences.Count().Should().Be(7); + var s = mockProj.Items.Select(p => $"ItemType = {p.ItemType}, Include = {p.Include}"); + Console.WriteLine(string.Join(Environment.NewLine, s)); + + return mockProj; } } } From 23a44f192f5556d9b01a04d23c6107d0d4022192 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 1 Nov 2016 14:58:11 -0700 Subject: [PATCH 06/11] Fixing the test on windows. We need to use path.combine because of the forward/backward slashes for directory separation. --- .../Rules/GivenThatIWantToMigrateProjectDependencies.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs index 13648ef0e..b6aa8915a 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateProjectDependencies.cs @@ -253,9 +253,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests public void It_migrates_unqualified_dependencies_as_ProjectReference_when_a_matching_project_is_found() { var mockProj = MigrateProject("TestAppWithUnqualifiedDependencies", "ProjectA"); + var projectReferenceInclude = Path.Combine("..", "ProjectB", "ProjectB.csproj"); var projectReferences = mockProj.Items.Should().ContainSingle( - item => item.ItemType == "ProjectReference" && item.Include == "../ProjectB/ProjectB.csproj"); + item => item.ItemType == "ProjectReference" && item.Include == projectReferenceInclude); } private ProjectRootElement MigrateProject(string solution, string project) From 155ef033f2429541886f88aa606c6be317493255 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 1 Nov 2016 12:10:51 -1000 Subject: [PATCH 07/11] Migrate: auto-inject test dependency version (#4565) * Migrate: auto-injected dependencies should overwrite existing dependency version if present * Address PR comments --- .../ConstantPackageVersions.cs | 3 + .../PackageConstants.cs | 65 ++++++++++++++----- .../MigratePackageDependenciesAndToolsRule.cs | 32 ++++----- .../GivenThatIWantToMigrateAspNetTools.cs | 2 +- ...enThatIWantToMigratePackageDependencies.cs | 49 ++++++++++++-- 5 files changed, 111 insertions(+), 40 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs index 3071fb81d..6a0597418 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ConstantPackageVersions.cs @@ -6,5 +6,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration internal class ConstantPackageVersions { public const string AspNetToolsVersion = "1.0.0-rc1-final"; + public const string TestSdkPackageVersion = "15.0.0-preview-20161024-02"; + public const string XUnitPackageVersion = "2.2.0-beta3-build3402"; + public const string XUnitRunnerPackageVersion = "2.2.0-beta4-build1188"; } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs index a4822a176..f897d09be 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs @@ -5,32 +5,65 @@ 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 TestSdkPackageVersion = "15.0.0-preview-20161024-02"; public const string XUnitPackageName = "xunit"; - public const string XUnitPackageVersion = "2.2.0-beta3-build3402"; public const string XUnitRunnerPackageName = "xunit.runner.visualstudio"; - public const string XUnitRunnerPackageVersion = "2.2.0-beta4-build1188"; - public static readonly IDictionary AspProjectDependencyToolsPackages = new Dictionary { - {"Microsoft.EntityFrameworkCore.Tools", "Microsoft.EntityFrameworkCore.Tools"}, - {"Microsoft.AspNetCore.Razor.Tools", "Microsoft.AspNetCore.Razor.Design"}, - {"Microsoft.AspNetCore.Razor.Design", "Microsoft.AspNetCore.Razor.Design"}, - {"Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "Microsoft.VisualStudio.Web.CodGeneration.Design"}, - {"Microsoft.VisualStudio.Web.CodeGeneration.Tools", ""}, + public static readonly IDictionary ProjectDependencyPackages = + new Dictionary { + {"Microsoft.EntityFrameworkCore.Tools", new PackageDependencyInfo { + Name = "Microsoft.EntityFrameworkCore.Tools", + Version = ConstantPackageVersions.AspNetToolsVersion } }, + { "Microsoft.AspNetCore.Razor.Tools", new PackageDependencyInfo { + Name = "Microsoft.AspNetCore.Razor.Design", + Version = ConstantPackageVersions.AspNetToolsVersion } }, + { "Microsoft.AspNetCore.Razor.Design", new PackageDependencyInfo { + Name = "Microsoft.AspNetCore.Razor.Design", + Version = ConstantPackageVersions.AspNetToolsVersion } }, + { "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 } }, }; - public static readonly IDictionary AspProjectToolsPackages = new Dictionary { - {"Microsoft.EntityFrameworkCore.Tools", "Microsoft.EntityFrameworkCore.Tools.DotNet"}, - {"Microsoft.AspNetCore.Razor.Tools", "Microsoft.AspNetCore.Razor.Tools"}, - {"Microsoft.VisualStudio.Web.CodeGeneration.Tools", "Microsoft.VisualStudio.Web.CodeGeneration.Tools"}, - {"Microsoft.DotNet.Watcher.Tools", "Microsoft.DotNet.Watcher.Tools"}, - {"Microsoft.Extensions.SecretManager.Tools", "Microsoft.Extensions.SecretManager.Tools"}, - {"Microsoft.AspNetCore.Server.IISIntegration.Tools", ""} + public static readonly IDictionary ProjectToolPackages = + new Dictionary { + {"Microsoft.EntityFrameworkCore.Tools", new PackageDependencyInfo { + Name = "Microsoft.EntityFrameworkCore.Tools.DotNet", + Version = ConstantPackageVersions.AspNetToolsVersion } }, + { "Microsoft.AspNetCore.Razor.Tools", new PackageDependencyInfo { + Name = "Microsoft.AspNetCore.Razor.Tools", + Version = ConstantPackageVersions.AspNetToolsVersion } }, + { "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} }; } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index ab203101d..a9f04e13c 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -108,7 +108,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules new PackageDependencyInfo { Name = PackageConstants.TestSdkPackageName, - Version = PackageConstants.TestSdkPackageVersion + Version = ConstantPackageVersions.TestSdkPackageVersion }), noFrameworkPackageReferenceItemGroup, mergeExisting: false); @@ -120,7 +120,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules new PackageDependencyInfo { Name = PackageConstants.XUnitPackageName, - Version = PackageConstants.XUnitPackageVersion + Version = ConstantPackageVersions.XUnitPackageVersion }), noFrameworkPackageReferenceItemGroup, mergeExisting: false); @@ -130,7 +130,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules new PackageDependencyInfo { Name = PackageConstants.XUnitRunnerPackageName, - Version = PackageConstants.XUnitRunnerPackageVersion + Version = ConstantPackageVersions.XUnitRunnerPackageVersion }), noFrameworkPackageReferenceItemGroup, mergeExisting: false); @@ -186,7 +186,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules _transformApplicator.Execute( ToolTransform().Transform(ToPackageDependencyInfo( tool, - PackageConstants.AspProjectToolsPackages)), + PackageConstants.ProjectToolPackages)), itemGroup, mergeExisting: true); } @@ -243,7 +243,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules _transformApplicator.Execute( transform.Transform(ToPackageDependencyInfo( packageDependency, - PackageConstants.AspProjectDependencyToolsPackages)), + PackageConstants.ProjectDependencyPackages)), itemGroup, mergeExisting: true); } @@ -251,22 +251,23 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules private PackageDependencyInfo ToPackageDependencyInfo( ProjectLibraryDependency dependency, - IDictionary toolsDictionary) + IDictionary dependencyToVersionMap) { var name = dependency.Name; var version = dependency.LibraryRange?.VersionRange?.OriginalString; - if (toolsDictionary.ContainsKey(name)) + if (dependencyToVersionMap.ContainsKey(name)) { - name = toolsDictionary[name]; - version = ConstantPackageVersions.AspNetToolsVersion; - - if(string.IsNullOrEmpty(name)) + var dependencyInfo = dependencyToVersionMap[name]; + if (dependencyInfo == null) { return null; } - } + name = dependencyInfo.Name; + version = dependencyInfo.Version; + } + return new PackageDependencyInfo { Name = name, @@ -391,12 +392,5 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules "PackageTargetFallback", t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}", t => t.Imports.OrEmptyIfNull().Any()); - - private class PackageDependencyInfo - { - public string Name {get; set;} - public string Version {get; set;} - public string PrivateAssets {get; set;} - } } } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs index ec4423710..7702dcd71 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs @@ -15,7 +15,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests [InlineData("Microsoft.EntityFrameworkCore.Tools", "Microsoft.EntityFrameworkCore.Tools", ConstantPackageVersions.AspNetToolsVersion)] [InlineData("Microsoft.AspNetCore.Razor.Tools", "Microsoft.AspNetCore.Razor.Design", ConstantPackageVersions.AspNetToolsVersion)] [InlineData("Microsoft.AspNetCore.Razor.Design", "Microsoft.AspNetCore.Razor.Design", ConstantPackageVersions.AspNetToolsVersion)] - [InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "Microsoft.VisualStudio.Web.CodGeneration.Design", 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( string sourceToolName, string targetToolName, diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 50066736f..0fd10e329 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -273,7 +273,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests }"); mockProj.Items.Should().ContainSingle( - i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference")); + i => (i.Include == "Microsoft.NET.Test.Sdk" && + i.ItemType == "PackageReference" && + i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02")); mockProj.Items.Should().NotContain( i => (i.Include == "xunit" && i.ItemType == "PackageReference")); @@ -297,13 +299,52 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests }"); mockProj.Items.Should().ContainSingle( - i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference")); + i => (i.Include == "Microsoft.NET.Test.Sdk" && + i.ItemType == "PackageReference" && + i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02")); mockProj.Items.Should().ContainSingle( - i => (i.Include == "xunit" && i.ItemType == "PackageReference")); + i => (i.Include == "xunit" && + i.ItemType == "PackageReference" && + i.GetMetadataWithName("Version").Value == "2.2.0-beta3-build3402")); mockProj.Items.Should().ContainSingle( - i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference")); + i => (i.Include == "xunit.runner.visualstudio" && + i.ItemType == "PackageReference" && + i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188")); + } + + [Fact] + public void It_migrates_test_projects_to_have_test_sdk_and_xunit_packagedependencies_overwrite_existing_packagedependencies() + { + var mockProj = RunPackageDependenciesRuleOnPj(@" + { + ""buildOptions"": { + ""emitEntryPoint"": true + }, + ""dependencies"": { + ""xunit"": ""2.2.0-beta3-build3330"" + }, + ""frameworks"": { + ""netcoreapp1.0"": {} + }, + ""testRunner"": ""xunit"" + }"); + + mockProj.Items.Should().ContainSingle( + i => (i.Include == "Microsoft.NET.Test.Sdk" && + i.ItemType == "PackageReference" && + i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02")); + + mockProj.Items.Should().ContainSingle( + i => (i.Include == "xunit" && + i.ItemType == "PackageReference" && + i.GetMetadataWithName("Version").Value == "2.2.0-beta3-build3402")); + + mockProj.Items.Should().ContainSingle( + i => (i.Include == "xunit.runner.visualstudio" && + i.ItemType == "PackageReference" && + i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188")); } private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple[] packageSpecs) From 57d79bb2d35b44ea3f1269a7c655e0b4cc0248b7 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 31 Oct 2016 16:34:37 -0700 Subject: [PATCH 08/11] When Library add reference to NETStandardLib if not present --- .../LibraryWithNetStandardLibRef/.noautobuild | 1 + .../LibraryWithNetStandardLibRef/Program.cs | 5 ++ .../LibraryWithNetStandardLibRef/project.json | 10 +++ .../.noautobuild | 1 + .../Program.cs | 5 ++ .../project.json | 9 +++ .../PackageConstants.cs | 2 + .../ProjectExtensions.cs | 72 +++++++++---------- .../ProjectType.cs | 5 +- .../MigratePackageDependenciesAndToolsRule.cs | 15 ++++ ...enThatIWantToMigratePackageDependencies.cs | 30 ++++++++ .../GivenThatIWantToMigrateTestApps.cs | 13 ++++ 12 files changed, 130 insertions(+), 38 deletions(-) create mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild create mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs create mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json create mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild create mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs create mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild new file mode 100644 index 000000000..8f7edc4ac --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild @@ -0,0 +1 @@ +noautobuild \ No newline at end of file diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs new file mode 100644 index 000000000..79ddf6c75 --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs @@ -0,0 +1,5 @@ +using System; + +class Program +{ +} diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json new file mode 100644 index 000000000..519b9beee --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json @@ -0,0 +1,10 @@ +{ + "frameworks": { + "netstandard1.3": { + "dependencies": { + "System.AppContext": "4.1.0", + "NETStandard.Library": "1.5.0" + } + } + } +} diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild new file mode 100644 index 000000000..8f7edc4ac --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild @@ -0,0 +1 @@ +noautobuild \ No newline at end of file diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs new file mode 100644 index 000000000..79ddf6c75 --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs @@ -0,0 +1,5 @@ +using System; + +class Program +{ +} diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json new file mode 100644 index 000000000..2ef2a4a2c --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json @@ -0,0 +1,9 @@ +{ + "frameworks": { + "netstandard1.3": { + "dependencies": { + "System.AppContext": "4.1.0" + } + } + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs index f897d09be..6317b2a71 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs @@ -19,6 +19,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk"; public const string XUnitPackageName = "xunit"; public const string XUnitRunnerPackageName = "xunit.runner.visualstudio"; + public const string NetStandardPackageName = "NETStandard.Library"; + public const string NetStandardPackageVersion = "1.6.0"; public static readonly IDictionary ProjectDependencyPackages = new Dictionary { diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs index a2e754d26..9bca917b0 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs @@ -13,59 +13,59 @@ namespace Microsoft.DotNet.ProjectJsonMigration { public static ProjectType GetProjectType(this Project project) { - var projectType = ProjectType.Console; - if (project.IsWebProject()) - { - projectType = ProjectType.Web; - } - else if (project.IsTestProject) + ProjectType projectType = ProjectType.Library; + if (project.IsTestProject) { projectType = ProjectType.Test; } + else if (project.HasEntryPoint()) + { + if (project.HasDependency(ContainingName(".AspNetCore."))) + { + projectType = ProjectType.Web; + } + else + { + projectType = ProjectType.Console; + } + } return projectType; } - private static bool IsWebProject(this Project project) + private static bool HasEntryPoint(this Project project) { - if(project.IsTestProject) - { - return false; - } + return project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault(); + } - var isExecutable = project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault(); - if (isExecutable - && project.HasAnyPackageContainingName(".AspNetCore.")) + private static Func ContainingName(string nameSegment) + { + return x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1; + } + + public static bool HasDependency(this Project project, Func pred) + { + if (HasAnyDependency(project.Dependencies, pred)) { return true; } + foreach (var tf in project.GetTargetFrameworks()) + { + if(HasAnyDependency(tf.Dependencies, pred)) + { + return true; + } + } + return false; } - private static bool HasAnyPackageContainingName(this Project project, string nameSegment) + private static bool HasAnyDependency( + IEnumerable dependencies, + Func pred) { - var containsPackageName = HasAnyPackageContainingName( - new ReadOnlyCollection(project.Dependencies), - nameSegment); - foreach (var tf in project.GetTargetFrameworks()) - { - if(containsPackageName) - { - break; - } - - containsPackageName = HasAnyPackageContainingName(tf.Dependencies, nameSegment); - } - - return containsPackageName; - } - - private static bool HasAnyPackageContainingName( - IReadOnlyList dependencies, - string nameSegment) - { - return dependencies.Any(x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1); + return dependencies.Any(pred); } } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs index 659ee6d5d..93349d576 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs @@ -3,7 +3,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration internal enum ProjectType { Console, - Web, - Test + Library, + Test, + Web } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index a9f04e13c..c6a3ff2e2 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -136,6 +136,21 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules mergeExisting: false); } break; + case ProjectType.Library: + if (!project.HasDependency( + (dep) => dep.Name.Trim().ToLower() == PackageConstants.NetStandardPackageName.ToLower())) + { + _transformApplicator.Execute( + PackageDependencyInfoTransform().Transform( + new PackageDependencyInfo + { + Name = PackageConstants.NetStandardPackageName, + Version = PackageConstants.NetStandardPackageVersion + }), + noFrameworkPackageReferenceItemGroup, + mergeExisting: true); + } + break; default: break; } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 0fd10e329..4170568fe 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -347,6 +347,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188")); } + [Theory] + [InlineData(@" + { + ""frameworks"": { + ""netstandard1.3"": { + ""dependencies"": { + ""System.AppContext"": ""4.1.0"", + ""NETStandard.Library"": ""1.5.0"" + } + } + } + }")] + [InlineData(@" + { + ""frameworks"": { + ""netstandard1.3"": { + ""dependencies"": { + ""System.AppContext"": ""4.1.0"" + } + } + } + }")] + public void It_migrates_library_and_does_not_double_netstandard_ref(string pjContent) + { + var mockProj = RunPackageDependenciesRuleOnPj(pjContent); + + mockProj.Items.Should().ContainSingle( + i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference")); + } + private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple[] packageSpecs) { foreach (var packageSpec in packageSpecs) diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index a411de556..c954d0206 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -423,6 +423,19 @@ namespace Microsoft.DotNet.Migration.Tests .Count().Should().Be(1); } + [Theory] + [InlineData("LibraryWithoutNetStandardLibRef")] + [InlineData("LibraryWithNetStandardLibRef")] + public void It_migrates_and_builds_library(string projectName) + { + var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, + callingMethod: $"{nameof(It_migrates_and_builds_library)}-projectName").Path; + + MigrateProject(projectDirectory); + Restore(projectDirectory, projectName); + BuildMSBuild(projectDirectory, projectName); + } + private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent) { if (projectName != null) From 875e275e38a7ed465ada931bece9ba83e8703ea2 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 31 Oct 2016 16:34:37 -0700 Subject: [PATCH 09/11] Revert "When Library add reference to NETStandardLib if not present" This reverts commit 57d79bb2d35b44ea3f1269a7c655e0b4cc0248b7. --- .../LibraryWithNetStandardLibRef/.noautobuild | 1 - .../LibraryWithNetStandardLibRef/Program.cs | 5 -- .../LibraryWithNetStandardLibRef/project.json | 10 --- .../.noautobuild | 1 - .../Program.cs | 5 -- .../project.json | 9 --- .../PackageConstants.cs | 2 - .../ProjectExtensions.cs | 70 +++++++++---------- .../ProjectType.cs | 5 +- .../MigratePackageDependenciesAndToolsRule.cs | 15 ---- ...enThatIWantToMigratePackageDependencies.cs | 30 -------- .../GivenThatIWantToMigrateTestApps.cs | 13 ---- 12 files changed, 37 insertions(+), 129 deletions(-) delete mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild delete mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs delete mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json delete mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild delete mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs delete mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild deleted file mode 100644 index 8f7edc4ac..000000000 --- a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild +++ /dev/null @@ -1 +0,0 @@ -noautobuild \ No newline at end of file diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs deleted file mode 100644 index 79ddf6c75..000000000 --- a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System; - -class Program -{ -} diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json deleted file mode 100644 index 519b9beee..000000000 --- a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "frameworks": { - "netstandard1.3": { - "dependencies": { - "System.AppContext": "4.1.0", - "NETStandard.Library": "1.5.0" - } - } - } -} diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild deleted file mode 100644 index 8f7edc4ac..000000000 --- a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild +++ /dev/null @@ -1 +0,0 @@ -noautobuild \ No newline at end of file diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs deleted file mode 100644 index 79ddf6c75..000000000 --- a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System; - -class Program -{ -} diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json deleted file mode 100644 index 2ef2a4a2c..000000000 --- a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "frameworks": { - "netstandard1.3": { - "dependencies": { - "System.AppContext": "4.1.0" - } - } - } -} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs index 6317b2a71..f897d09be 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs @@ -19,8 +19,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk"; public const string XUnitPackageName = "xunit"; public const string XUnitRunnerPackageName = "xunit.runner.visualstudio"; - public const string NetStandardPackageName = "NETStandard.Library"; - public const string NetStandardPackageVersion = "1.6.0"; public static readonly IDictionary ProjectDependencyPackages = new Dictionary { diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs index 9bca917b0..a2e754d26 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs @@ -13,59 +13,59 @@ namespace Microsoft.DotNet.ProjectJsonMigration { public static ProjectType GetProjectType(this Project project) { - ProjectType projectType = ProjectType.Library; - if (project.IsTestProject) + var projectType = ProjectType.Console; + if (project.IsWebProject()) + { + projectType = ProjectType.Web; + } + else if (project.IsTestProject) { projectType = ProjectType.Test; } - else if (project.HasEntryPoint()) - { - if (project.HasDependency(ContainingName(".AspNetCore."))) - { - projectType = ProjectType.Web; - } - else - { - projectType = ProjectType.Console; - } - } return projectType; } - private static bool HasEntryPoint(this Project project) + private static bool IsWebProject(this Project project) { - return project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault(); - } - - private static Func ContainingName(string nameSegment) - { - return x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1; - } - - public static bool HasDependency(this Project project, Func pred) - { - if (HasAnyDependency(project.Dependencies, pred)) + if(project.IsTestProject) { - return true; + return false; } - foreach (var tf in project.GetTargetFrameworks()) + var isExecutable = project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault(); + if (isExecutable + && project.HasAnyPackageContainingName(".AspNetCore.")) { - if(HasAnyDependency(tf.Dependencies, pred)) - { - return true; - } + return true; } return false; } - private static bool HasAnyDependency( - IEnumerable dependencies, - Func pred) + private static bool HasAnyPackageContainingName(this Project project, string nameSegment) { - return dependencies.Any(pred); + var containsPackageName = HasAnyPackageContainingName( + new ReadOnlyCollection(project.Dependencies), + nameSegment); + foreach (var tf in project.GetTargetFrameworks()) + { + if(containsPackageName) + { + break; + } + + containsPackageName = HasAnyPackageContainingName(tf.Dependencies, nameSegment); + } + + return containsPackageName; + } + + private static bool HasAnyPackageContainingName( + IReadOnlyList dependencies, + string nameSegment) + { + return dependencies.Any(x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1); } } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs index 93349d576..659ee6d5d 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs @@ -3,8 +3,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration internal enum ProjectType { Console, - Library, - Test, - Web + Web, + Test } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index c6a3ff2e2..a9f04e13c 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -136,21 +136,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules mergeExisting: false); } break; - case ProjectType.Library: - if (!project.HasDependency( - (dep) => dep.Name.Trim().ToLower() == PackageConstants.NetStandardPackageName.ToLower())) - { - _transformApplicator.Execute( - PackageDependencyInfoTransform().Transform( - new PackageDependencyInfo - { - Name = PackageConstants.NetStandardPackageName, - Version = PackageConstants.NetStandardPackageVersion - }), - noFrameworkPackageReferenceItemGroup, - mergeExisting: true); - } - break; default: break; } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 4170568fe..0fd10e329 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -347,36 +347,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188")); } - [Theory] - [InlineData(@" - { - ""frameworks"": { - ""netstandard1.3"": { - ""dependencies"": { - ""System.AppContext"": ""4.1.0"", - ""NETStandard.Library"": ""1.5.0"" - } - } - } - }")] - [InlineData(@" - { - ""frameworks"": { - ""netstandard1.3"": { - ""dependencies"": { - ""System.AppContext"": ""4.1.0"" - } - } - } - }")] - public void It_migrates_library_and_does_not_double_netstandard_ref(string pjContent) - { - var mockProj = RunPackageDependenciesRuleOnPj(pjContent); - - mockProj.Items.Should().ContainSingle( - i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference")); - } - private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple[] packageSpecs) { foreach (var packageSpec in packageSpecs) diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index c954d0206..a411de556 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -423,19 +423,6 @@ namespace Microsoft.DotNet.Migration.Tests .Count().Should().Be(1); } - [Theory] - [InlineData("LibraryWithoutNetStandardLibRef")] - [InlineData("LibraryWithNetStandardLibRef")] - public void It_migrates_and_builds_library(string projectName) - { - var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, - callingMethod: $"{nameof(It_migrates_and_builds_library)}-projectName").Path; - - MigrateProject(projectDirectory); - Restore(projectDirectory, projectName); - BuildMSBuild(projectDirectory, projectName); - } - private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent) { if (projectName != null) From e3bc102b0622cb18013f9d1a6b06c48f23355b23 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 31 Oct 2016 16:34:37 -0700 Subject: [PATCH 10/11] When Library add reference to NETStandardLib if not present --- .../LibraryWithNetStandardLibRef/.noautobuild | 1 + .../LibraryWithNetStandardLibRef/Program.cs | 5 ++ .../LibraryWithNetStandardLibRef/project.json | 10 +++ .../.noautobuild | 1 + .../Program.cs | 5 ++ .../project.json | 9 +++ .../PackageConstants.cs | 2 + .../ProjectExtensions.cs | 72 +++++++++---------- .../ProjectType.cs | 5 +- .../MigratePackageDependenciesAndToolsRule.cs | 15 ++++ .../GivenThatIWantToMigrateAspNetTools.cs | 5 +- ...enThatIWantToMigratePackageDependencies.cs | 30 ++++++++ .../GivenThatIWantToMigrateTestApps.cs | 13 ++++ 13 files changed, 134 insertions(+), 39 deletions(-) create mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild create mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs create mode 100644 TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json create mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild create mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs create mode 100644 TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild new file mode 100644 index 000000000..8f7edc4ac --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/.noautobuild @@ -0,0 +1 @@ +noautobuild \ No newline at end of file diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs new file mode 100644 index 000000000..79ddf6c75 --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/Program.cs @@ -0,0 +1,5 @@ +using System; + +class Program +{ +} diff --git a/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json new file mode 100644 index 000000000..519b9beee --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithNetStandardLibRef/project.json @@ -0,0 +1,10 @@ +{ + "frameworks": { + "netstandard1.3": { + "dependencies": { + "System.AppContext": "4.1.0", + "NETStandard.Library": "1.5.0" + } + } + } +} diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild new file mode 100644 index 000000000..8f7edc4ac --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/.noautobuild @@ -0,0 +1 @@ +noautobuild \ No newline at end of file diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs new file mode 100644 index 000000000..79ddf6c75 --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/Program.cs @@ -0,0 +1,5 @@ +using System; + +class Program +{ +} diff --git a/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json new file mode 100644 index 000000000..2ef2a4a2c --- /dev/null +++ b/TestAssets/TestProjects/LibraryWithoutNetStandardLibRef/project.json @@ -0,0 +1,9 @@ +{ + "frameworks": { + "netstandard1.3": { + "dependencies": { + "System.AppContext": "4.1.0" + } + } + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs index f897d09be..6317b2a71 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/PackageConstants.cs @@ -19,6 +19,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk"; public const string XUnitPackageName = "xunit"; public const string XUnitRunnerPackageName = "xunit.runner.visualstudio"; + public const string NetStandardPackageName = "NETStandard.Library"; + public const string NetStandardPackageVersion = "1.6.0"; public static readonly IDictionary ProjectDependencyPackages = new Dictionary { diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs index a2e754d26..9bca917b0 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectExtensions.cs @@ -13,59 +13,59 @@ namespace Microsoft.DotNet.ProjectJsonMigration { public static ProjectType GetProjectType(this Project project) { - var projectType = ProjectType.Console; - if (project.IsWebProject()) - { - projectType = ProjectType.Web; - } - else if (project.IsTestProject) + ProjectType projectType = ProjectType.Library; + if (project.IsTestProject) { projectType = ProjectType.Test; } + else if (project.HasEntryPoint()) + { + if (project.HasDependency(ContainingName(".AspNetCore."))) + { + projectType = ProjectType.Web; + } + else + { + projectType = ProjectType.Console; + } + } return projectType; } - private static bool IsWebProject(this Project project) + private static bool HasEntryPoint(this Project project) { - if(project.IsTestProject) - { - return false; - } + return project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault(); + } - var isExecutable = project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault(); - if (isExecutable - && project.HasAnyPackageContainingName(".AspNetCore.")) + private static Func ContainingName(string nameSegment) + { + return x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1; + } + + public static bool HasDependency(this Project project, Func pred) + { + if (HasAnyDependency(project.Dependencies, pred)) { return true; } + foreach (var tf in project.GetTargetFrameworks()) + { + if(HasAnyDependency(tf.Dependencies, pred)) + { + return true; + } + } + return false; } - private static bool HasAnyPackageContainingName(this Project project, string nameSegment) + private static bool HasAnyDependency( + IEnumerable dependencies, + Func pred) { - var containsPackageName = HasAnyPackageContainingName( - new ReadOnlyCollection(project.Dependencies), - nameSegment); - foreach (var tf in project.GetTargetFrameworks()) - { - if(containsPackageName) - { - break; - } - - containsPackageName = HasAnyPackageContainingName(tf.Dependencies, nameSegment); - } - - return containsPackageName; - } - - private static bool HasAnyPackageContainingName( - IReadOnlyList dependencies, - string nameSegment) - { - return dependencies.Any(x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1); + return dependencies.Any(pred); } } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs index 659ee6d5d..93349d576 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectType.cs @@ -3,7 +3,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration internal enum ProjectType { Console, - Web, - Test + Library, + Test, + Web } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index a9f04e13c..c6a3ff2e2 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -136,6 +136,21 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules mergeExisting: false); } break; + case ProjectType.Library: + if (!project.HasDependency( + (dep) => dep.Name.Trim().ToLower() == PackageConstants.NetStandardPackageName.ToLower())) + { + _transformApplicator.Execute( + PackageDependencyInfoTransform().Transform( + new PackageDependencyInfo + { + Name = PackageConstants.NetStandardPackageName, + Version = PackageConstants.NetStandardPackageVersion + }), + noFrameworkPackageReferenceItemGroup, + mergeExisting: true); + } + break; default: break; } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs index 7702dcd71..f7fc798b8 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateAspNetTools.cs @@ -44,7 +44,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } }"); - var packageRef = mockProj.Items.Where(i => i.Include != "Microsoft.NET.Sdk" && i.ItemType == "PackageReference").Should().BeEmpty(); + var packageRef = mockProj.Items.Where(i => + i.Include != "Microsoft.NET.Sdk" && + i.Include != "NETStandard.Library" && + i.ItemType == "PackageReference").Should().BeEmpty(); } [Theory] diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 0fd10e329..4170568fe 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -347,6 +347,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188")); } + [Theory] + [InlineData(@" + { + ""frameworks"": { + ""netstandard1.3"": { + ""dependencies"": { + ""System.AppContext"": ""4.1.0"", + ""NETStandard.Library"": ""1.5.0"" + } + } + } + }")] + [InlineData(@" + { + ""frameworks"": { + ""netstandard1.3"": { + ""dependencies"": { + ""System.AppContext"": ""4.1.0"" + } + } + } + }")] + public void It_migrates_library_and_does_not_double_netstandard_ref(string pjContent) + { + var mockProj = RunPackageDependenciesRuleOnPj(pjContent); + + mockProj.Items.Should().ContainSingle( + i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference")); + } + private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple[] packageSpecs) { foreach (var packageSpec in packageSpecs) diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index a411de556..c954d0206 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -423,6 +423,19 @@ namespace Microsoft.DotNet.Migration.Tests .Count().Should().Be(1); } + [Theory] + [InlineData("LibraryWithoutNetStandardLibRef")] + [InlineData("LibraryWithNetStandardLibRef")] + public void It_migrates_and_builds_library(string projectName) + { + var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, + callingMethod: $"{nameof(It_migrates_and_builds_library)}-projectName").Path; + + MigrateProject(projectDirectory); + Restore(projectDirectory, projectName); + BuildMSBuild(projectDirectory, projectName); + } + private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent) { if (projectName != null) From 3f7a21339fd28405871871b2943b3a73d565bed5 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 1 Nov 2016 18:57:32 -0700 Subject: [PATCH 11/11] Fix typo in dotnet test help message --- src/dotnet/commands/dotnet-test/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index be2a8cf97..d8c9e6a00 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Tools.Test CommandOptionType.SingleValue); var outputOption = cmd.Option( - "-o|--output ", + "-o|--output ", @"Directory in which to find the binaries to be run", CommandOptionType.SingleValue);