-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow publishing file-based apps #49310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
be499ce
d8955ca
9f69d76
d7c9d45
0e1233e
44fd7ec
ce4d9e4
27e6d9f
01dd25a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable disable | ||
|
||
using System.CommandLine; | ||
using Microsoft.DotNet.Cli.Commands.Restore; | ||
using Microsoft.DotNet.Cli.Commands.Run; | ||
using Microsoft.DotNet.Cli.Extensions; | ||
|
||
namespace Microsoft.DotNet.Cli.Commands.Publish; | ||
|
@@ -14,49 +13,75 @@ public class PublishCommand : RestoringCommand | |
private PublishCommand( | ||
IEnumerable<string> msbuildArgs, | ||
bool noRestore, | ||
string msbuildPath = null) | ||
string? msbuildPath = null) | ||
: base(msbuildArgs, noRestore, msbuildPath) | ||
{ | ||
} | ||
|
||
public static PublishCommand FromArgs(string[] args, string msbuildPath = null) | ||
public static CommandBase FromArgs(string[] args, string? msbuildPath = null) | ||
{ | ||
var parser = Parser.Instance; | ||
var parseResult = parser.ParseFrom("dotnet publish", args); | ||
return FromParseResult(parseResult); | ||
} | ||
|
||
public static PublishCommand FromParseResult(ParseResult parseResult, string msbuildPath = null) | ||
public static CommandBase FromParseResult(ParseResult parseResult, string? msbuildPath = null) | ||
{ | ||
parseResult.HandleDebugSwitch(); | ||
parseResult.ShowHelpOrErrorIfAppropriate(); | ||
|
||
var msbuildArgs = new List<string>() | ||
{ | ||
"-target:Publish", | ||
"--property:_IsPublishing=true" // This property will not hold true for MSBuild /t:Publish or in VS. | ||
}; | ||
|
||
IEnumerable<string> slnOrProjectArgs = parseResult.GetValue(PublishCommandParser.SlnOrProjectArgument); | ||
string[] args = parseResult.GetValue(PublishCommandParser.SlnOrProjectOrFileArgument) ?? []; | ||
|
||
LoggerUtility.SeparateBinLogArguments(args, out var binLogArgs, out var nonBinLogArgs); | ||
|
||
CommonOptions.ValidateSelfContainedOptions(parseResult.HasOption(PublishCommandParser.SelfContainedOption), | ||
parseResult.HasOption(PublishCommandParser.NoSelfContainedOption)); | ||
|
||
msbuildArgs.AddRange(parseResult.OptionValuesToBeForwarded(PublishCommandParser.GetCommand())); | ||
|
||
bool noBuild = parseResult.HasOption(PublishCommandParser.NoBuildOption); | ||
|
||
bool noRestore = noBuild || parseResult.HasOption(PublishCommandParser.NoRestoreOption); | ||
|
||
if (nonBinLogArgs is [{ } arg] && VirtualProjectBuildingCommand.IsValidEntryPointPath(arg)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chsienki has a PR out to remove the need for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't need any adjusting - Chris's logic lives inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Def want it to work. I just want to make sure we're confident these PRs will converge correctly. |
||
{ | ||
if (!parseResult.HasOption(PublishCommandParser.ConfigurationOption)) | ||
{ | ||
msbuildArgs.Add("-p:Configuration=Release"); | ||
} | ||
|
||
msbuildArgs.AddRange(binLogArgs); | ||
|
||
return new VirtualProjectBuildingCommand( | ||
entryPointFileFullPath: Path.GetFullPath(arg), | ||
msbuildArgs: msbuildArgs, | ||
verbosity: parseResult.GetValue(CommonOptions.VerbosityOption), | ||
interactive: parseResult.GetValue(CommonOptions.InteractiveMsBuildForwardOption)) | ||
{ | ||
NoBuild = noBuild, | ||
NoRestore = noRestore, | ||
NoCache = true, | ||
BuildTarget = "Publish", | ||
}; | ||
} | ||
|
||
ReleasePropertyProjectLocator projectLocator = new(parseResult, MSBuildPropertyNames.PUBLISH_RELEASE, | ||
new ReleasePropertyProjectLocator.DependentCommandOptions( | ||
parseResult.GetValue(PublishCommandParser.SlnOrProjectArgument), | ||
nonBinLogArgs, | ||
parseResult.HasOption(PublishCommandParser.ConfigurationOption) ? parseResult.GetValue(PublishCommandParser.ConfigurationOption) : null, | ||
parseResult.HasOption(PublishCommandParser.FrameworkOption) ? parseResult.GetValue(PublishCommandParser.FrameworkOption) : null | ||
) | ||
); | ||
msbuildArgs.AddRange(projectLocator.GetCustomDefaultConfigurationValueIfSpecified()); | ||
|
||
msbuildArgs.AddRange(slnOrProjectArgs ?? []); | ||
msbuildArgs.AddRange(args ?? []); | ||
|
||
bool noRestore = parseResult.HasOption(PublishCommandParser.NoRestoreOption) | ||
|| parseResult.HasOption(PublishCommandParser.NoBuildOption); | ||
msbuildArgs.Insert(0, "-target:Publish"); | ||
|
||
return new PublishCommand( | ||
msbuildArgs, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -62,7 +62,7 @@ internal sealed class VirtualProjectBuildingCommand : CommandBase | |||||
|
||||||
public VirtualProjectBuildingCommand( | ||||||
string entryPointFileFullPath, | ||||||
string[] msbuildArgs, | ||||||
IReadOnlyList<string> msbuildArgs, | ||||||
VerbosityOptions? verbosity, | ||||||
bool interactive) | ||||||
{ | ||||||
|
@@ -77,12 +77,12 @@ public VirtualProjectBuildingCommand( | |||||
|
||||||
public string EntryPointFileFullPath { get; } | ||||||
public Dictionary<string, string> GlobalProperties { get; } | ||||||
public string[] BinaryLoggerArgs { get; } | ||||||
public IReadOnlyList<string> BinaryLoggerArgs { get; } | ||||||
public VerbosityOptions Verbosity { get; } | ||||||
public bool NoRestore { get; init; } | ||||||
public bool NoCache { get; init; } | ||||||
public bool NoBuild { get; init; } | ||||||
public bool NoIncremental { get; init; } | ||||||
public string? BuildTarget { get; init; } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
That would remove an annotation but get the same result. |
||||||
|
||||||
public override int Execute() | ||||||
{ | ||||||
|
@@ -170,7 +170,7 @@ public override int Execute() | |||||
{ | ||||||
var buildRequest = new BuildRequestData( | ||||||
CreateProjectInstance(projectCollection), | ||||||
targetsToBuild: [NoIncremental ? "Rebuild" : "Build"]); | ||||||
targetsToBuild: [BuildTarget ?? "Build"]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Could do this if you take the above suggestion. |
||||||
var buildResult = BuildManager.DefaultBuildManager.BuildRequest(buildRequest); | ||||||
if (buildResult.OverallResult != BuildResultCode.Success) | ||||||
{ | ||||||
|
@@ -201,10 +201,10 @@ public override int Execute() | |||||
consoleLogger.Shutdown(); | ||||||
} | ||||||
|
||||||
static ILogger? GetBinaryLogger(string[] args) | ||||||
static ILogger? GetBinaryLogger(IReadOnlyList<string> args) | ||||||
{ | ||||||
// Like in MSBuild, only the last binary logger is used. | ||||||
for (int i = args.Length - 1; i >= 0; i--) | ||||||
for (int i = args.Count - 1; i >= 0; i--) | ||||||
{ | ||||||
var arg = args[i]; | ||||||
if (LoggerUtility.IsBinLogArgument(arg)) | ||||||
|
@@ -540,6 +540,7 @@ public static void WriteProjectFile( | |||||
<TargetFramework>net10.0</TargetFramework> | ||||||
<ImplicitUsings>enable</ImplicitUsings> | ||||||
<Nullable>enable</Nullable> | ||||||
<PublishAot>true</PublishAot> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we unconditionally do this? What if the user has the following code? #:property PublishAot false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The project will get |
||||||
</PropertyGroup> | ||||||
"""); | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we mention here that this default to AOT and how to override that if it's not desirable?