@@ -42,6 +42,7 @@ int Run(string[] args)
4242 . Add ( " [msbuild args] Examples: " )
4343 . Add ( " - Automatically restore: -r" )
4444 . Add ( " - Set normal MSBuild verbosity: -v:n" )
45+ . Add ( " - Set minimal MSBuild verbosity: -v:m" )
4546 . Add ( " - Build configuration: -p:Configuration=Release" ) ;
4647
4748 extra = options . Parse ( args ) ;
@@ -116,18 +117,53 @@ int Execute()
116117 if ( File . Exists ( file ) )
117118 File . Delete ( file ) ;
118119
119- // Optimize the "build" so that it doesn't actually do a full compile if possible.
120+ var slnTargets = $ "after.{ Path . GetFileName ( project ) } .targets";
121+ var deleteSlnTargets = false ;
120122 var contentsOnly = false ;
121- if ( ! Execute ( DotnetMuxer . Path . FullName , $ "msbuild { project } { string . Join ( ' ' , extra ) } -p:dotnet-nugetize=\" { file } \" -t:\" GetPackageContents;Pack\" ") )
122- return - 1 ;
123123
124- if ( ! File . Exists ( file ) )
124+ try
125125 {
126- // Re-run requesting contents only.
127- if ( ! Execute ( DotnetMuxer . Path . FullName , $ "msbuild { project } { string . Join ( ' ' , extra ) } -p:dotnet-nugetize-contents=true -p:dotnet-nugetize=\" { file } \" -t:\" GetPackageContents\" ") )
126+ if ( project . EndsWith ( ".sln" ) && ! File . Exists ( slnTargets ) )
127+ {
128+ File . WriteAllText ( slnTargets , EmbeddedResource . GetContent ( "after.sln.targets" ) , Encoding . UTF8 ) ;
129+ deleteSlnTargets = true ;
130+ }
131+
132+ // Optimize the "build" so that it doesn't actually do a full compile if possible.
133+ if ( ! Execute ( DotnetMuxer . Path . FullName , $ "msbuild { project } { string . Join ( ' ' , extra ) } -p:dotnet-nugetize=\" { file } \" -t:\" GetPackageContents;Pack\" ") )
134+ {
135+ // The error might have been caused by us not being able to write our slnTargets
136+ if ( project . EndsWith ( ".sln" ) && ! deleteSlnTargets )
137+ ColorConsole . WriteLine ( $ "Solution targets '{ slnTargets } ' already exists. NuGetizing all projects in the solution is therefore required.". Yellow ( ) ) ;
138+
128139 return - 1 ;
140+ }
141+
142+ if ( ! File . Exists ( file ) )
143+ {
144+ // Re-run requesting contents only.
145+ if ( ! Execute ( DotnetMuxer . Path . FullName , $ "msbuild { project } { string . Join ( ' ' , extra ) } -p:dotnet-nugetize-contents=true -p:dotnet-nugetize=\" { file } \" -t:\" GetPackageContents\" ") )
146+ {
147+ // The error might have been caused by us not being able to write our slnTargets
148+ if ( project . EndsWith ( ".sln" ) && ! deleteSlnTargets )
149+ ColorConsole . WriteLine ( $ "Solution targets '{ slnTargets } ' already exists. NuGetizing all projects in the solution is therefore required.". Yellow ( ) ) ;
129150
130- contentsOnly = true ;
151+ return - 1 ;
152+ }
153+
154+ contentsOnly = true ;
155+ }
156+ }
157+ finally
158+ {
159+ if ( File . Exists ( slnTargets ) && deleteSlnTargets )
160+ File . Delete ( slnTargets ) ;
161+ }
162+
163+ if ( ! File . Exists ( file ) )
164+ {
165+ ColorConsole . WriteLine ( "Failed to discover nugetized content." . Red ( ) ) ;
166+ return - 1 ;
131167 }
132168
133169 var doc = XDocument . Load ( file ) ;
0 commit comments