Merge pull request #2580 from dotnet/brthor/2566
Fix Using Command.Create from a Desktop Application
This commit is contained in:
commit
ef0c3b2cee
9 changed files with 141 additions and 18 deletions
|
@ -0,0 +1,21 @@
|
||||||
|
using System;
|
||||||
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace DesktopAppWhichCallsDotnet
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static int Main(string[] args)
|
||||||
|
{
|
||||||
|
var projectPath = args[0];
|
||||||
|
|
||||||
|
return Command.CreateDotNet("build", new string[] {})
|
||||||
|
.WorkingDirectory(Path.GetDirectoryName(projectPath))
|
||||||
|
.ForwardStdErr()
|
||||||
|
.ForwardStdOut()
|
||||||
|
.Execute()
|
||||||
|
.ExitCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0-*",
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.DotNet.Cli.Utils": "1.0.0-*"
|
||||||
|
},
|
||||||
|
"compilationOptions": {
|
||||||
|
"emitEntryPoint": true
|
||||||
|
},
|
||||||
|
"frameworks": {
|
||||||
|
"net451": {}
|
||||||
|
}
|
||||||
|
}
|
12
TestAssets/TestProjects/TestAppSimple/Program.cs
Normal file
12
TestAssets/TestProjects/TestAppSimple/Program.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ConsoleApplication
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
TestAssets/TestProjects/TestAppSimple/project.json
Normal file
22
TestAssets/TestProjects/TestAppSimple/project.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0-*",
|
||||||
|
"compilationOptions": {
|
||||||
|
"emitEntryPoint": true
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.NETCore.App": "1.0.0-rc2-*"
|
||||||
|
},
|
||||||
|
"frameworks": {
|
||||||
|
"netcoreapp1.0": { }
|
||||||
|
},
|
||||||
|
"runtimes": {
|
||||||
|
"win7-x64": {},
|
||||||
|
"win7-x86": {},
|
||||||
|
"osx.10.10-x64": {},
|
||||||
|
"osx.10.11-x64": {},
|
||||||
|
"ubuntu.14.04-x64": {},
|
||||||
|
"centos.7-x64": {},
|
||||||
|
"rhel.7.2-x64": {},
|
||||||
|
"debian.8-x64": {}
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,7 +59,10 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[Target(nameof(RestoreTestAssetPackages), nameof(BuildTestAssetPackages))]
|
[Target(nameof(RestoreTestAssetPackages), nameof(BuildTestAssetPackages))]
|
||||||
public static BuildTargetResult SetupTestPackages(BuildTargetContext c) => c.Success();
|
public static BuildTargetResult SetupTestPackages(BuildTargetContext c) => c.Success();
|
||||||
|
|
||||||
[Target(nameof(RestoreTestAssetProjects), nameof(RestoreDesktopTestAssetProjects), nameof(BuildTestAssetProjects))]
|
[Target(nameof(RestoreTestAssetProjects),
|
||||||
|
nameof(RestoreDesktopTestAssetProjects),
|
||||||
|
nameof(BuildTestAssetProjects),
|
||||||
|
nameof(BuildDesktopTestAssetProjects))]
|
||||||
public static BuildTargetResult SetupTestProjects(BuildTargetContext c) => c.Success();
|
public static BuildTargetResult SetupTestProjects(BuildTargetContext c) => c.Success();
|
||||||
|
|
||||||
[Target]
|
[Target]
|
||||||
|
@ -236,25 +239,22 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[Target]
|
[Target]
|
||||||
public static BuildTargetResult BuildTestAssetProjects(BuildTargetContext c)
|
public static BuildTargetResult BuildTestAssetProjects(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"));
|
var testAssetsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects");
|
||||||
|
|
||||||
var dotnet = DotNetCli.Stage2;
|
var dotnet = DotNetCli.Stage2;
|
||||||
var nobuildFileName = ".noautobuild";
|
var framework = "netcoreapp1.0";
|
||||||
string testProjectsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects");
|
|
||||||
var projects = Directory.GetFiles(testProjectsRoot, "project.json", SearchOption.AllDirectories)
|
|
||||||
.Where(p => !ConditionalTestAssets.Where(s => !s.Skip() && p.EndsWith(Path.Combine(s.Path, "project.json"))).Any())
|
|
||||||
.Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), nobuildFileName)));
|
|
||||||
|
|
||||||
foreach (var project in projects)
|
return BuildTestAssets(c, testAssetsRoot, dotnet, framework);
|
||||||
{
|
|
||||||
c.Info($"Building: {project}");
|
|
||||||
dotnet.Build("--framework", "netcoreapp1.0")
|
|
||||||
.WorkingDirectory(Path.GetDirectoryName(project))
|
|
||||||
.Execute()
|
|
||||||
.EnsureSuccessful();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Success();
|
[Target]
|
||||||
|
[BuildPlatforms(BuildPlatform.Windows)]
|
||||||
|
public static BuildTargetResult BuildDesktopTestAssetProjects(BuildTargetContext c)
|
||||||
|
{
|
||||||
|
var testAssetsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "DesktopTestProjects");
|
||||||
|
var dotnet = DotNetCli.Stage2;
|
||||||
|
var framework = "net451";
|
||||||
|
|
||||||
|
return BuildTestAssets(c, testAssetsRoot, dotnet, framework);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Target]
|
[Target]
|
||||||
|
@ -359,6 +359,28 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static BuildTargetResult BuildTestAssets(BuildTargetContext c, string testAssetsRoot, DotNetCli dotnet, string framework)
|
||||||
|
{
|
||||||
|
CleanBinObj(c, testAssetsRoot);
|
||||||
|
|
||||||
|
var nobuildFileName = ".noautobuild";
|
||||||
|
|
||||||
|
var projects = Directory.GetFiles(testAssetsRoot, "project.json", SearchOption.AllDirectories)
|
||||||
|
.Where(p => !ConditionalTestAssets.Where(s => !s.Skip() && p.EndsWith(Path.Combine(s.Path, "project.json"))).Any())
|
||||||
|
.Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), nobuildFileName)));
|
||||||
|
|
||||||
|
foreach (var project in projects)
|
||||||
|
{
|
||||||
|
c.Info($"Building: {project}");
|
||||||
|
dotnet.Build("--framework", framework)
|
||||||
|
.WorkingDirectory(Path.GetDirectoryName(project))
|
||||||
|
.Execute()
|
||||||
|
.EnsureSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Success();
|
||||||
|
}
|
||||||
|
|
||||||
private static Dictionary<string, string> LoadVsVars(BuildTargetContext c)
|
private static Dictionary<string, string> LoadVsVars(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
|
|
@ -27,7 +27,8 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
FileName = commandSpec.Path,
|
FileName = commandSpec.Path,
|
||||||
Arguments = commandSpec.Args,
|
Arguments = commandSpec.Args,
|
||||||
RedirectStandardError = true,
|
RedirectStandardError = true,
|
||||||
RedirectStandardOutput = true
|
RedirectStandardOutput = true,
|
||||||
|
UseShellExecute = false
|
||||||
};
|
};
|
||||||
|
|
||||||
_stdOut = new StreamForwarder();
|
_stdOut = new StreamForwarder();
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
using FluentAssertions;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
|
{
|
||||||
|
public class GivenADesktopAppWhichUsesCommandCreateDotnet : TestBase
|
||||||
|
{
|
||||||
|
[WindowsOnlyFact]
|
||||||
|
public void It_calls_dotnet_build_on_a_project_successfully()
|
||||||
|
{
|
||||||
|
var testAssetsManager = GetTestGroupTestAssetsManager("DesktopTestProjects");
|
||||||
|
var testInstance = testAssetsManager
|
||||||
|
.CreateTestInstance("DesktopAppWhichCallsDotnet")
|
||||||
|
.WithLockFiles()
|
||||||
|
.WithBuildArtifacts();
|
||||||
|
|
||||||
|
var testProjectAssetManager = GetTestGroupTestAssetsManager("TestProjects");
|
||||||
|
var testInstanceToBuild = testProjectAssetManager
|
||||||
|
.CreateTestInstance("TestAppSimple")
|
||||||
|
.WithLockFiles();
|
||||||
|
|
||||||
|
var testProject = Path.Combine(testInstance.TestRoot, "project.json");
|
||||||
|
var testProjectToBuild = Path.Combine(testInstanceToBuild.TestRoot, "project.json");
|
||||||
|
|
||||||
|
new RunCommand(testProject).Execute(testProjectToBuild).Should().Pass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue