Do no pass down to implicit restore the framework option.

This commit is contained in:
Livar Cunha 2017-06-13 00:04:25 -07:00
parent 94e728b9ab
commit 5e5b4de0b9
16 changed files with 242 additions and 24 deletions

View file

@ -0,0 +1,24 @@
// 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 Helper
{
/// <summary>
/// Gets the message from the helper. This comment is here to help test XML documentation file generation, please do not remove it.
/// </summary>
/// <returns>A message</returns>
public static string GetMessage()
{
return "This string came from the test library!";
}
public static void SayHi()
{
Console.WriteLine("Hello there!");
}
}
}

View file

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,24 @@
// 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 TestLibrary;
using Xunit;
namespace TestNamespace
{
public class VSTestXunitTests
{
[Fact]
public void VSTestXunitPassTest()
{
Assert.Equal("This string came from the test library!", Helper.GetMessage());
}
[Fact]
public void VSTestXunitFailTest()
{
Assert.Equal(2, 2);
}
}
}

View file

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../TestLibrary/TestLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(CLI_TestPlatform_Version)" />
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta4-build1194" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TestLibrary\TestLibrary.csproj" />
</ItemGroup>
</Project>

View file

@ -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 TestApp
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine(TestLibrary.Helper.GetMessage());
}
}
}

View file

@ -12,31 +12,36 @@ namespace Microsoft.DotNet.Tools
{ {
private bool NoRestore { get; } private bool NoRestore { get; }
private IEnumerable<string> ArgsToForward { get; } private IEnumerable<string> ParsedArguments { get; }
private IEnumerable<string> TrailingArguments { get; }
private IEnumerable<string> ArgsToForwardToRestore() private IEnumerable<string> ArgsToForwardToRestore()
{ {
var restoreArguments = ArgsToForward.Where(a => var restoreArguments = ParsedArguments.Where(a =>
!a.StartsWith("/t:") && !a.StartsWith("/p:TargetFramework"));
!a.StartsWith("/target:") &&
!a.StartsWith("/ConsoleLoggerParameters:") &&
!a.StartsWith("/clp:"));
if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:"))) if (!restoreArguments.Any(a => a.StartsWith("/verbosity:")))
{ {
restoreArguments = restoreArguments.Concat(new string[] { "/v:q" }); restoreArguments = restoreArguments.Concat(new string[] { "/verbosity:q" });
} }
return restoreArguments; return restoreArguments.Concat(TrailingArguments);
} }
private bool ShouldRunImplicitRestore => !NoRestore; private bool ShouldRunImplicitRestore => !NoRestore;
public RestoringCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null) public RestoringCommand(
IEnumerable<string> msbuildArgs,
IEnumerable<string> parsedArguments,
IEnumerable<string> trailingArguments,
bool noRestore,
string msbuildPath = null)
: base(msbuildArgs, msbuildPath) : base(msbuildArgs, msbuildPath)
{ {
NoRestore = noRestore; NoRestore = noRestore;
ArgsToForward = msbuildArgs; ParsedArguments = parsedArguments;
TrailingArguments = trailingArguments;
} }
public override int Execute() public override int Execute()

View file

@ -15,8 +15,13 @@ namespace Microsoft.DotNet.Tools.Build
{ {
public class BuildCommand : RestoringCommand public class BuildCommand : RestoringCommand
{ {
public BuildCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null) public BuildCommand(
: base(msbuildArgs, noRestore, msbuildPath) IEnumerable<string> msbuildArgs,
IEnumerable<string> userDefinedArguments,
IEnumerable<string> trailingArguments,
bool noRestore,
string msbuildPath = null)
: base(msbuildArgs, userDefinedArguments, trailingArguments, noRestore, msbuildPath)
{ {
} }
@ -49,7 +54,12 @@ namespace Microsoft.DotNet.Tools.Build
bool noRestore = appliedBuildOptions.HasOption("--no-restore"); bool noRestore = appliedBuildOptions.HasOption("--no-restore");
return new BuildCommand(msbuildArgs, noRestore, msbuildPath); return new BuildCommand(
msbuildArgs,
appliedBuildOptions.OptionValuesToBeForwarded(),
appliedBuildOptions.Arguments,
noRestore,
msbuildPath);
} }
public static int Run(string[] args) public static int Run(string[] args)

View file

@ -14,8 +14,13 @@ namespace Microsoft.DotNet.Tools.Pack
{ {
public class PackCommand : RestoringCommand public class PackCommand : RestoringCommand
{ {
public PackCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null) public PackCommand(
: base(msbuildArgs, noRestore, msbuildPath) IEnumerable<string> msbuildArgs,
IEnumerable<string> userDefinedArguments,
IEnumerable<string> trailingArguments,
bool noRestore,
string msbuildPath = null)
: base(msbuildArgs, userDefinedArguments, trailingArguments, noRestore, msbuildPath)
{ {
} }
@ -40,7 +45,12 @@ namespace Microsoft.DotNet.Tools.Pack
bool noRestore = parsedPack.HasOption("--no-restore"); bool noRestore = parsedPack.HasOption("--no-restore");
return new PackCommand(msbuildArgs, noRestore, msbuildPath); return new PackCommand(
msbuildArgs,
parsedPack.OptionValuesToBeForwarded(),
parsedPack.Arguments,
noRestore,
msbuildPath);
} }
public static int Run(string[] args) public static int Run(string[] args)

View file

@ -13,8 +13,13 @@ namespace Microsoft.DotNet.Tools.Publish
{ {
public class PublishCommand : RestoringCommand public class PublishCommand : RestoringCommand
{ {
private PublishCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null) private PublishCommand(
: base(msbuildArgs, noRestore, msbuildPath) IEnumerable<string> msbuildArgs,
IEnumerable<string> userDefinedArguments,
IEnumerable<string> trailingArguments,
bool noRestore,
string msbuildPath = null)
: base(msbuildArgs, userDefinedArguments, trailingArguments, noRestore, msbuildPath)
{ {
} }
@ -40,7 +45,12 @@ namespace Microsoft.DotNet.Tools.Publish
bool noRestore = appliedPublishOption.HasOption("--no-restore"); bool noRestore = appliedPublishOption.HasOption("--no-restore");
return new PublishCommand(msbuildArgs, noRestore, msbuildPath); return new PublishCommand(
msbuildArgs,
appliedPublishOption.OptionValuesToBeForwarded(),
appliedPublishOption.Arguments,
noRestore,
msbuildPath);
} }
public static int Run(string[] args) public static int Run(string[] args)

View file

@ -145,7 +145,8 @@ namespace Microsoft.DotNet.Tools.Run
buildArgs.AddRange(RestoreArgs); buildArgs.AddRange(RestoreArgs);
var buildResult = new RestoringCommand(buildArgs, NoRestore).Execute(); var buildResult =
new RestoringCommand(buildArgs, RestoreArgs, new [] { Project }, NoRestore).Execute();
if (buildResult != 0) if (buildResult != 0)
{ {
Reporter.Error.WriteLine(); Reporter.Error.WriteLine();

View file

@ -16,8 +16,13 @@ namespace Microsoft.DotNet.Tools.Test
{ {
public class TestCommand : RestoringCommand public class TestCommand : RestoringCommand
{ {
public TestCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null) public TestCommand(
: base(msbuildArgs, noRestore, msbuildPath) IEnumerable<string> msbuildArgs,
IEnumerable<string> userDefinedArguments,
IEnumerable<string> trailingArguments,
bool noRestore,
string msbuildPath = null)
: base(msbuildArgs, userDefinedArguments, trailingArguments, noRestore, msbuildPath)
{ {
} }
@ -67,7 +72,12 @@ namespace Microsoft.DotNet.Tools.Test
bool noRestore = parsedTest.HasOption("--no-restore"); bool noRestore = parsedTest.HasOption("--no-restore");
return new TestCommand(msbuildArgs, noRestore, msbuildPath); return new TestCommand(
msbuildArgs,
parsedTest.OptionValuesToBeForwarded(),
parsedTest.Arguments,
noRestore,
msbuildPath);
} }
public static int Run(string[] args) public static int Run(string[] args)

View file

@ -4,6 +4,7 @@
using System; using System;
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit; using Xunit;
using System.Linq; using System.Linq;
@ -52,6 +53,23 @@ namespace Microsoft.DotNet.Cli.Build.Tests
.Should().Pass(); .Should().Pass();
} }
[Fact]
public void ItCanBuildAMultiTFMProjectWithImplicitRestore()
{
var testInstance = TestAssets.Get(
TestAssetKinds.DesktopTestProjects,
"NETFrameworkReferenceNETStandard20")
.CreateInstance()
.WithSourceFiles();
string projectDirectory = Path.Combine(testInstance.Root.FullName, "MultiTFMTestApp");
new BuildCommand()
.WithWorkingDirectory(projectDirectory)
.Execute("--framework netcoreapp2.0")
.Should().Pass();
}
[Fact] [Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenBuildingWithTheNoRestoreOption() public void ItDoesNotImplicitlyRestoreAProjectWhenBuildingWithTheNoRestoreOption()
{ {

View file

@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions; using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit; using Xunit;
@ -60,6 +61,23 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.Should().Pass(); .Should().Pass();
} }
[Fact]
public void ItCanPublishAMultiTFMProjectWithImplicitRestore()
{
var testInstance = TestAssets.Get(
TestAssetKinds.DesktopTestProjects,
"NETFrameworkReferenceNETStandard20")
.CreateInstance()
.WithSourceFiles();
string projectDirectory = Path.Combine(testInstance.Root.FullName, "MultiTFMTestApp");
new PublishCommand()
.WithWorkingDirectory(projectDirectory)
.Execute("--framework netcoreapp2.0")
.Should().Pass();
}
[Fact] [Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenPublishingWithTheNoRestoreOption() public void ItDoesNotImplicitlyRestoreAProjectWhenPublishingWithTheNoRestoreOption()
{ {

View file

@ -3,6 +3,7 @@
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit; using Xunit;
@ -54,6 +55,24 @@ namespace Microsoft.DotNet.Cli.Run.Tests
.And.HaveStdOutContaining("Hello World!"); .And.HaveStdOutContaining("Hello World!");
} }
[Fact]
public void ItCanRunAMultiTFMProjectWithImplicitRestore()
{
var testInstance = TestAssets.Get(
TestAssetKinds.DesktopTestProjects,
"NETFrameworkReferenceNETStandard20")
.CreateInstance()
.WithSourceFiles();
string projectDirectory = Path.Combine(testInstance.Root.FullName, "MultiTFMTestApp");
new RunCommand()
.WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput("--framework netcoreapp2.0")
.Should().Pass()
.And.HaveStdOutContaining("This string came from the test library!");
}
[Fact] [Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenRunningWithTheNoRestoreOption() public void ItDoesNotImplicitlyRestoreAProjectWhenRunningWithTheNoRestoreOption()
{ {

View file

@ -7,6 +7,7 @@ using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using System.IO; using System.IO;
using System; using System;
using Xunit;
namespace Microsoft.DotNet.Cli.Test.Tests namespace Microsoft.DotNet.Cli.Test.Tests
{ {
@ -75,5 +76,22 @@ namespace Microsoft.DotNet.Cli.Test.Tests
result.StdOut.Should().Contain("Failed TestNamespace.VSTestXunitTests.VSTestXunitFailTestNetCoreApp"); result.StdOut.Should().Contain("Failed TestNamespace.VSTestXunitTests.VSTestXunitFailTestNetCoreApp");
result.ExitCode.Should().Be(1); result.ExitCode.Should().Be(1);
} }
[Fact]
public void ItCanTestAMultiTFMProjectWithImplicitRestore()
{
var testInstance = TestAssets.Get(
TestAssetKinds.DesktopTestProjects,
"MultiTFMXunitProject")
.CreateInstance()
.WithSourceFiles();
string projectDirectory = Path.Combine(testInstance.Root.FullName, "XUnitProject");
new DotnetTestCommand()
.WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --framework netcoreapp2.0")
.Should().Pass();
}
} }
} }