11using System ;
22using System . Collections . Generic ;
3- using System . ComponentModel ;
43using System . IO ;
54using System . Linq ;
65using System . Text ;
76using BenchmarkDotNet . Characteristics ;
8- using BenchmarkDotNet . Environments ;
97using BenchmarkDotNet . Extensions ;
108using BenchmarkDotNet . Jobs ;
119using BenchmarkDotNet . Loggers ;
@@ -20,6 +18,10 @@ public class DotNetCliCommand
2018 {
2119 [ PublicAPI ] public string CliPath { get ; }
2220
21+ [ PublicAPI ] public string FilePath { get ; }
22+
23+ [ PublicAPI ] public string TargetFrameworkMoniker { get ; }
24+
2325 [ PublicAPI ] public string Arguments { get ; }
2426
2527 [ PublicAPI ] public GenerateResult GenerateResult { get ; }
@@ -34,11 +36,13 @@ public class DotNetCliCommand
3436
3537 [ PublicAPI ] public bool LogOutput { get ; }
3638
37- public DotNetCliCommand ( string cliPath , string arguments , GenerateResult generateResult , ILogger logger ,
39+ public DotNetCliCommand ( string cliPath , string filePath , string tfm , string arguments , GenerateResult generateResult , ILogger logger ,
3840 BuildPartition buildPartition , IReadOnlyList < EnvironmentVariable > environmentVariables , TimeSpan timeout , bool logOutput = false )
3941 {
4042 CliPath = cliPath ?? DotNetCliCommandExecutor . DefaultDotNetCliPath . Value ;
4143 Arguments = arguments ;
44+ FilePath = filePath ;
45+ TargetFrameworkMoniker = tfm ;
4246 GenerateResult = generateResult ;
4347 Logger = logger ;
4448 BuildPartition = buildPartition ;
@@ -48,10 +52,13 @@ public DotNetCliCommand(string cliPath, string arguments, GenerateResult generat
4852 }
4953
5054 public DotNetCliCommand WithArguments ( string arguments )
51- => new ( CliPath , arguments , GenerateResult , Logger , BuildPartition , EnvironmentVariables , Timeout , logOutput : LogOutput ) ;
55+ => new ( CliPath , arguments , FilePath , TargetFrameworkMoniker , GenerateResult , Logger , BuildPartition , EnvironmentVariables , Timeout , LogOutput ) ;
56+
57+ public DotNetCliCommand WithFilePath ( string filePath )
58+ => new ( CliPath , Arguments , filePath , TargetFrameworkMoniker , GenerateResult , Logger , BuildPartition , EnvironmentVariables , Timeout , LogOutput ) ;
5259
5360 public DotNetCliCommand WithCliPath ( string cliPath )
54- => new ( cliPath , Arguments , GenerateResult , Logger , BuildPartition , EnvironmentVariables , Timeout , logOutput : LogOutput ) ;
61+ => new ( cliPath , Arguments , FilePath , TargetFrameworkMoniker , GenerateResult , Logger , BuildPartition , EnvironmentVariables , Timeout , LogOutput ) ;
5562
5663 [ PublicAPI ]
5764 public BuildResult RestoreThenBuild ( )
@@ -69,12 +76,12 @@ public BuildResult RestoreThenBuild()
6976 if ( BuildPartition . ForcedNoDependenciesForIntegrationTests )
7077 {
7178 var restoreResult = DotNetCliCommandExecutor . Execute ( WithArguments (
72- GetRestoreCommand ( GenerateResult . ArtifactsPaths , BuildPartition , $ "{ Arguments } --no-dependencies", "restore-no-deps" , excludeOutput : true ) ) ) ;
79+ GetRestoreCommand ( GenerateResult . ArtifactsPaths , BuildPartition , FilePath , $ "{ Arguments } --no-dependencies", "restore-no-deps" , excludeOutput : true ) ) ) ;
7380 if ( ! restoreResult . IsSuccess )
7481 return BuildResult . Failure ( GenerateResult , restoreResult . AllInformation ) ;
7582
7683 return DotNetCliCommandExecutor . Execute ( WithArguments (
77- GetBuildCommand ( GenerateResult . ArtifactsPaths , BuildPartition , $ "{ Arguments } --no-restore --no-dependencies", "build-no-restore-no-deps" , excludeOutput : true ) ) )
84+ GetBuildCommand ( GenerateResult . ArtifactsPaths , BuildPartition , FilePath , $ "{ Arguments } --no-restore --no-dependencies", "build-no-restore-no-deps" , excludeOutput : true ) ) )
7885 . ToBuildResult ( GenerateResult ) ;
7986 }
8087 else
@@ -110,28 +117,30 @@ public BuildResult RestoreThenBuildThenPublish()
110117
111118 public DotNetCliCommandResult Restore ( )
112119 => DotNetCliCommandExecutor . Execute ( WithArguments (
113- GetRestoreCommand ( GenerateResult . ArtifactsPaths , BuildPartition , Arguments , "restore" ) ) ) ;
120+ GetRestoreCommand ( GenerateResult . ArtifactsPaths , BuildPartition , FilePath , Arguments , "restore" ) ) ) ;
114121
115122 public DotNetCliCommandResult Build ( )
116123 => DotNetCliCommandExecutor . Execute ( WithArguments (
117- GetBuildCommand ( GenerateResult . ArtifactsPaths , BuildPartition , Arguments , "build" ) ) ) ;
124+ GetBuildCommand ( GenerateResult . ArtifactsPaths , BuildPartition , FilePath , Arguments , "build" ) ) ) ;
118125
119126 public DotNetCliCommandResult BuildNoRestore ( )
120127 => DotNetCliCommandExecutor . Execute ( WithArguments (
121- GetBuildCommand ( GenerateResult . ArtifactsPaths , BuildPartition , $ "{ Arguments } --no-restore", "build-no-restore" ) ) ) ;
128+ GetBuildCommand ( GenerateResult . ArtifactsPaths , BuildPartition , FilePath , $ "{ Arguments } --no-restore", "build-no-restore" ) ) ) ;
122129
123130 public DotNetCliCommandResult Publish ( )
124131 => DotNetCliCommandExecutor . Execute ( WithArguments (
125- GetPublishCommand ( GenerateResult . ArtifactsPaths , BuildPartition , Arguments , "publish" ) ) ) ;
132+ GetPublishCommand ( GenerateResult . ArtifactsPaths , BuildPartition , FilePath , Arguments , "publish" ) ) ) ;
126133
127134 // PublishNoBuildAndNoRestore was removed because we set --output in the build step. We use the implicit build included in the publish command.
128135 public DotNetCliCommandResult PublishNoRestore ( )
129136 => DotNetCliCommandExecutor . Execute ( WithArguments (
130- GetPublishCommand ( GenerateResult . ArtifactsPaths , BuildPartition , $ "{ Arguments } --no-restore", "publish-no-restore" ) ) ) ;
137+ GetPublishCommand ( GenerateResult . ArtifactsPaths , BuildPartition , FilePath , $ "{ Arguments } --no-restore", "publish-no-restore" ) ) ) ;
131138
132- internal static string GetRestoreCommand ( ArtifactsPaths artifactsPaths , BuildPartition buildPartition , string ? extraArguments = null , string ? binLogSuffix = null , bool excludeOutput = false )
139+ internal static string GetRestoreCommand ( ArtifactsPaths artifactsPaths , BuildPartition buildPartition , string filePath , string tfm , string ? extraArguments = null , string ? binLogSuffix = null , bool excludeOutput = false )
133140 => new StringBuilder ( )
134141 . AppendArgument ( "restore" )
142+ . AppendArgument ( $ "-f { tfm } ")
143+ . AppendArgument ( $ "\" { filePath } \" ")
135144 . AppendArgument ( string . IsNullOrEmpty ( artifactsPaths . PackagesDirectoryName ) ? string . Empty : $ "--packages \" { artifactsPaths . PackagesDirectoryName } \" ")
136145 . AppendArgument ( GetCustomMsBuildArguments ( buildPartition . RepresentativeBenchmarkCase , buildPartition . Resolver ) )
137146 . AppendArgument ( extraArguments )
@@ -140,9 +149,12 @@ internal static string GetRestoreCommand(ArtifactsPaths artifactsPaths, BuildPar
140149 . MaybeAppendOutputPaths ( artifactsPaths , true , excludeOutput )
141150 . ToString ( ) ;
142151
143- internal static string GetBuildCommand ( ArtifactsPaths artifactsPaths , BuildPartition buildPartition , string ? extraArguments = null , string ? binLogSuffix = null , bool excludeOutput = false )
152+ internal static string GetBuildCommand ( ArtifactsPaths artifactsPaths , BuildPartition buildPartition , string filePath , string tfm , string ? extraArguments = null , string ? binLogSuffix = null , bool excludeOutput = false )
144153 => new StringBuilder ( )
145- . AppendArgument ( $ "build -c { buildPartition . BuildConfiguration } ") // we don't need to specify TFM, our auto-generated project contains always single one
154+ . AppendArgument ( "build" )
155+ . AppendArgument ( $ "\" { filePath } \" ")
156+ . AppendArgument ( $ "-f { tfm } ")
157+ . AppendArgument ( $ "-c { buildPartition . BuildConfiguration } ")
146158 . AppendArgument ( GetCustomMsBuildArguments ( buildPartition . RepresentativeBenchmarkCase , buildPartition . Resolver ) )
147159 . AppendArgument ( extraArguments )
148160 . AppendArgument ( GetMandatoryMsBuildSettings ( buildPartition . BuildConfiguration ) )
@@ -151,9 +163,12 @@ internal static string GetBuildCommand(ArtifactsPaths artifactsPaths, BuildParti
151163 . MaybeAppendOutputPaths ( artifactsPaths , excludeOutput : excludeOutput )
152164 . ToString ( ) ;
153165
154- internal static string GetPublishCommand ( ArtifactsPaths artifactsPaths , BuildPartition buildPartition , string ? extraArguments = null , string ? binLogSuffix = null )
166+ internal static string GetPublishCommand ( ArtifactsPaths artifactsPaths , BuildPartition buildPartition , string filePath , string tfm , string ? extraArguments = null , string ? binLogSuffix = null )
155167 => new StringBuilder ( )
156- . AppendArgument ( $ "publish -c { buildPartition . BuildConfiguration } ") // we don't need to specify TFM, our auto-generated project contains always single one
168+ . AppendArgument ( "publish" )
169+ . AppendArgument ( $ "\" { filePath } \" ")
170+ . AppendArgument ( $ "-f { tfm } ")
171+ . AppendArgument ( $ "-c { buildPartition . BuildConfiguration } ")
157172 . AppendArgument ( GetCustomMsBuildArguments ( buildPartition . RepresentativeBenchmarkCase , buildPartition . Resolver ) )
158173 . AppendArgument ( extraArguments )
159174 . AppendArgument ( GetMandatoryMsBuildSettings ( buildPartition . BuildConfiguration ) )
0 commit comments