It is not currently possible when there is a -f|--framework argument because we cannot force a TargetFramework global property on to the restore evaluation. Doing so completely breaks restore by applying the TargetFramework to all projects transitively. The correct behavior is to restore for all frameworks, then build/publish/etc for the given target framework. Achieving that still requires two distinct msbuild invocations. This also changes the verbosity of implicit restore from quiet to that of the subsequent command (default=minimal). Similar to global properties, we cannot specify a distinct console verbosity for the /restore portion of the overall execution. For consistency, we apply the same verbosity change to the case where we still use two separate msbuild invocations. This also fixes an issue where the separate restore invocation's msbuild log would be overwritten by the subsequent command execution. However, this remains unfixed in the case where we still use two separate msbuild invocations.
67 lines
No EOL
1.8 KiB
C#
67 lines
No EOL
1.8 KiB
C#
// 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.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
using Microsoft.DotNet.Tools.MSBuild;
|
|
using Microsoft.DotNet.Cli;
|
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
|
|
|
namespace Microsoft.DotNet.Tools.Restore
|
|
{
|
|
public class RestoreCommand : MSBuildForwardingApp
|
|
{
|
|
public RestoreCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
|
: base(msbuildArgs, msbuildPath)
|
|
{
|
|
}
|
|
|
|
public static RestoreCommand FromArgs(string[] args, string msbuildPath = null, bool noLogo = true)
|
|
{
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
var parser = Parser.Instance;
|
|
|
|
var result = parser.ParseFrom("dotnet restore", args);
|
|
|
|
result.ShowHelpOrErrorIfAppropriate();
|
|
|
|
var parsedRestore = result["dotnet"]["restore"];
|
|
|
|
var msbuildArgs = new List<string>();
|
|
|
|
if (noLogo)
|
|
{
|
|
msbuildArgs.Add("/nologo");
|
|
}
|
|
|
|
msbuildArgs.Add("/t:Restore");
|
|
|
|
msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded());
|
|
|
|
msbuildArgs.AddRange(parsedRestore.Arguments);
|
|
|
|
return new RestoreCommand(msbuildArgs, msbuildPath);
|
|
}
|
|
|
|
public static int Run(string[] args)
|
|
{
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
RestoreCommand cmd;
|
|
try
|
|
{
|
|
cmd = FromArgs(args);
|
|
}
|
|
catch (CommandCreationException e)
|
|
{
|
|
return e.ExitCode;
|
|
}
|
|
|
|
return cmd.Execute();
|
|
}
|
|
}
|
|
} |