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