[WiP] enable /m by default (#4543)
* MSBuild integration project + refactoring * Feature Complete * Change default target to an existing one
This commit is contained in:
parent
5ede3b6367
commit
f53c51fc07
4 changed files with 104 additions and 11 deletions
32
TestAssets/TestProjects/MSBuildIntegration/build.proj
Normal file
32
TestAssets/TestProjects/MSBuildIntegration/build.proj
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Validate"
|
||||
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<Target Name="Build"
|
||||
DependsOnTargets="Validate" />
|
||||
|
||||
<Target Name="Clean"
|
||||
DependsOnTargets="Validate" />
|
||||
|
||||
<Target Name="Pack"
|
||||
DependsOnTargets="Validate" />
|
||||
|
||||
<Target Name="Publish"
|
||||
DependsOnTargets="Validate" />
|
||||
<Target Name="Restore"
|
||||
DependsOnTargets="Validate" />
|
||||
|
||||
<Target Name="VSTest"
|
||||
DependsOnTargets="Validate" />
|
||||
|
||||
<Target Name="Validate">
|
||||
<Error Condition=" $(MSBuildNodeCount) < 2 "
|
||||
Text="Expect MSBuildNodeCount to be greater than 1, but found $(MSBuildNodeCount). Is this a single proc machine?" />
|
||||
|
||||
<Error Condition=" '$(MSBuildExtensionsPath)' == '' "
|
||||
Text="Expect MSBuildExtensionsPath to be set, but it is not." />
|
||||
|
||||
<Error Condition=" '$(CscToolExe)' == '' "
|
||||
Text="Expect CscToolExe to be set, but it is not." />
|
||||
</Target>
|
||||
</Project>
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli;
|
||||
|
||||
|
@ -12,14 +13,25 @@ namespace Microsoft.DotNet.Tools.MSBuild
|
|||
public class MSBuildForwardingApp
|
||||
{
|
||||
private const string s_msbuildExeName = "MSBuild.dll";
|
||||
|
||||
private readonly ForwardingApp _forwardingApp;
|
||||
|
||||
private readonly Dictionary<string, string> _msbuildRequiredEnvironmentVariables =
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{ "MSBuildExtensionsPath", AppContext.BaseDirectory },
|
||||
{ "CscToolExe", GetRunCscPath() }
|
||||
};
|
||||
|
||||
private readonly IEnumerable<string> _msbuildRequiredParameters =
|
||||
new List<string> { "/m" };
|
||||
|
||||
public MSBuildForwardingApp(IEnumerable<string> argsToForward)
|
||||
{
|
||||
_forwardingApp = new ForwardingApp(
|
||||
GetMSBuildExePath(),
|
||||
argsToForward,
|
||||
environmentVariables: GetEnvironmentVariables());
|
||||
_msbuildRequiredParameters.Concat(argsToForward),
|
||||
environmentVariables: _msbuildRequiredEnvironmentVariables);
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
|
@ -27,15 +39,6 @@ namespace Microsoft.DotNet.Tools.MSBuild
|
|||
return _forwardingApp.Execute();
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> GetEnvironmentVariables()
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ "MSBuildExtensionsPath", AppContext.BaseDirectory },
|
||||
{ "CscToolExe", GetRunCscPath() }
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetMSBuildExePath()
|
||||
{
|
||||
return Path.Combine(
|
||||
|
|
35
test/msbuild.IntegrationTests/GivenDotnetInvokesMSBuild.cs
Normal file
35
test/msbuild.IntegrationTests/GivenDotnetInvokesMSBuild.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.MSBuild.IntegrationTests
|
||||
{
|
||||
public class GivenDotnetInvokesMSBuild : TestBase
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("build")]
|
||||
[InlineData("clean")]
|
||||
[InlineData("msbuild")]
|
||||
[InlineData("pack")]
|
||||
[InlineData("publish")]
|
||||
[InlineData("test")]
|
||||
public void When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(string command)
|
||||
{
|
||||
var testInstance = TestAssets.Get("MSBuildIntegration")
|
||||
.CreateInstance(identifier: command)
|
||||
.WithSourceFiles();
|
||||
|
||||
new DotnetCommand()
|
||||
.WithWorkingDirectory(testInstance.Root)
|
||||
.Execute(command)
|
||||
.Should().Pass();
|
||||
}
|
||||
}
|
||||
}
|
23
test/msbuild.IntegrationTests/project.json
Normal file
23
test/msbuild.IntegrationTests/project.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": {
|
||||
"target": "project"
|
||||
},
|
||||
"xunit": "2.2.0-beta3-build3330",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-330423-54"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"testRunner": "xunit"
|
||||
}
|
Loading…
Reference in a new issue