4
4
using System . Collections . ObjectModel ;
5
5
using System . CommandLine ;
6
6
using System . CommandLine . Parsing ;
7
- using System . Configuration ;
8
7
using Microsoft . DotNet . Cli . Commands . Build ;
9
8
using Microsoft . DotNet . Cli . Commands . Restore ;
9
+ using Microsoft . DotNet . Cli . Commands . Run ;
10
10
using Microsoft . DotNet . Cli . Extensions ;
11
11
using Microsoft . DotNet . Cli . NuGetPackageDownloader ;
12
12
using Microsoft . DotNet . Cli . Utils ;
13
13
using NuGet . Commands ;
14
14
using NuGet . Common ;
15
15
using NuGet . Packaging ;
16
- using NuGet . Packaging . Core ;
17
16
18
17
namespace Microsoft . DotNet . Cli . Commands . Pack ;
19
18
@@ -23,33 +22,54 @@ public class PackCommand(
23
22
string ? msbuildPath = null
24
23
) : RestoringCommand ( msbuildArgs , noRestore , msbuildPath : msbuildPath )
25
24
{
26
- public static PackCommand FromArgs ( string [ ] args , string ? msbuildPath = null )
25
+ public static CommandBase FromArgs ( string [ ] args , string ? msbuildPath = null )
27
26
{
28
27
var parseResult = Parser . Parse ( [ "dotnet" , "pack" , ..args ] ) ;
29
28
return FromParseResult ( parseResult , msbuildPath ) ;
30
29
}
31
30
32
- public static PackCommand FromParseResult ( ParseResult parseResult , string ? msbuildPath = null )
31
+ public static CommandBase FromParseResult ( ParseResult parseResult , string ? msbuildPath = null )
33
32
{
34
- var msbuildArgs = parseResult . OptionValuesToBeForwarded ( PackCommandParser . GetCommand ( ) ) . Concat ( parseResult . GetValue ( PackCommandParser . SlnOrProjectArgument ) ?? [ ] ) ;
35
-
36
- ReleasePropertyProjectLocator projectLocator = new ( parseResult , MSBuildPropertyNames . PACK_RELEASE ,
37
- new ReleasePropertyProjectLocator . DependentCommandOptions (
38
- parseResult . GetValue ( PackCommandParser . SlnOrProjectArgument ) ,
39
- parseResult . HasOption ( PackCommandParser . ConfigurationOption ) ? parseResult . GetValue ( PackCommandParser . ConfigurationOption ) : null
40
- )
41
- ) ;
42
-
43
- bool noRestore = parseResult . HasOption ( PackCommandParser . NoRestoreOption ) || parseResult . HasOption ( PackCommandParser . NoBuildOption ) ;
44
- var parsedMSBuildArgs = MSBuildArgs . AnalyzeMSBuildArguments (
45
- msbuildArgs ,
46
- CommonOptions . PropertiesOption ,
47
- CommonOptions . RestorePropertiesOption ,
48
- PackCommandParser . TargetOption ,
49
- PackCommandParser . VerbosityOption ) ;
50
- return new PackCommand (
51
- parsedMSBuildArgs . CloneWithAdditionalProperties ( projectLocator . GetCustomDefaultConfigurationValueIfSpecified ( ) ) ,
52
- noRestore ,
33
+ var args = parseResult . GetValue ( PackCommandParser . SlnOrProjectOrFileArgument ) ?? [ ] ;
34
+
35
+ LoggerUtility . SeparateBinLogArguments ( args , out var binLogArgs , out var nonBinLogArgs ) ;
36
+
37
+ bool noBuild = parseResult . HasOption ( PackCommandParser . NoBuildOption ) ;
38
+
39
+ bool noRestore = noBuild || parseResult . HasOption ( PackCommandParser . NoRestoreOption ) ;
40
+
41
+ return CommandFactory . CreateVirtualOrPhysicalCommand (
42
+ PackCommandParser . GetCommand ( ) ,
43
+ PackCommandParser . SlnOrProjectOrFileArgument ,
44
+ ( msbuildArgs , appFilePath ) => new VirtualProjectBuildingCommand (
45
+ entryPointFileFullPath : Path . GetFullPath ( appFilePath ) ,
46
+ msbuildArgs : msbuildArgs )
47
+ {
48
+ NoBuild = noBuild ,
49
+ NoRestore = noRestore ,
50
+ NoCache = true ,
51
+ } ,
52
+ ( msbuildArgs , msbuildPath ) =>
53
+ {
54
+ ReleasePropertyProjectLocator projectLocator = new ( parseResult , MSBuildPropertyNames . PACK_RELEASE ,
55
+ new ReleasePropertyProjectLocator . DependentCommandOptions (
56
+ nonBinLogArgs ,
57
+ parseResult . HasOption ( PackCommandParser . ConfigurationOption ) ? parseResult . GetValue ( PackCommandParser . ConfigurationOption ) : null
58
+ )
59
+ ) ;
60
+ return new PackCommand (
61
+ msbuildArgs . CloneWithAdditionalProperties ( projectLocator . GetCustomDefaultConfigurationValueIfSpecified ( ) ) ,
62
+ noRestore ,
63
+ msbuildPath ) ;
64
+ } ,
65
+ optionsToUseWhenParsingMSBuildFlags :
66
+ [
67
+ CommonOptions . PropertiesOption ,
68
+ CommonOptions . RestorePropertiesOption ,
69
+ PackCommandParser . TargetOption ,
70
+ PackCommandParser . VerbosityOption ,
71
+ ] ,
72
+ parseResult ,
53
73
msbuildPath ) ;
54
74
}
55
75
@@ -67,7 +87,7 @@ private static LogLevel MappingVerbosityToNugetLogLevel(VerbosityOptions? verbos
67
87
68
88
public static int RunPackCommand ( ParseResult parseResult )
69
89
{
70
- var args = parseResult . GetValue ( PackCommandParser . SlnOrProjectArgument ) ? . ToList ( ) ?? new List < string > ( ) ;
90
+ var args = parseResult . GetValue ( PackCommandParser . SlnOrProjectOrFileArgument ) ? . ToList ( ) ?? new List < string > ( ) ;
71
91
72
92
if ( args . Count != 1 )
73
93
{
@@ -112,7 +132,7 @@ public static int Run(ParseResult parseResult)
112
132
parseResult . HandleDebugSwitch ( ) ;
113
133
parseResult . ShowHelpOrErrorIfAppropriate ( ) ;
114
134
115
- var args = parseResult . GetValue ( PackCommandParser . SlnOrProjectArgument ) ? . ToList ( ) ?? new List < string > ( ) ;
135
+ var args = parseResult . GetValue ( PackCommandParser . SlnOrProjectOrFileArgument ) ? . ToList ( ) ?? new List < string > ( ) ;
116
136
117
137
if ( args . Count > 0 && Path . GetExtension ( args [ 0 ] ) . Equals ( ".nuspec" , StringComparison . OrdinalIgnoreCase ) )
118
138
{
0 commit comments