Skip to content

Commit d703e82

Browse files
committed
ManyDotNetSolutions: support for single-file programs.
1 parent 8c32fcb commit d703e82

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/PostSharp.Engineering.BuildTools/Build/Solutions/DotNetSolution.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class DotNetSolution : Solution
1818
{
1919
public DotNetSolution( string solutionPath ) : base( solutionPath ) { }
2020

21+
public bool IsSingleFile => Path.GetExtension( this.SolutionPath ).Equals( ".cs", StringComparison.OrdinalIgnoreCase );
22+
2123
public override bool Build( BuildContext context, BuildSettings settings ) => this.RunBuildOrTests( context, settings, test: false );
2224

2325
public override bool Pack( BuildContext context, BuildSettings settings )
@@ -73,7 +75,12 @@ private bool RunBuildOrTests(
7375
string command;
7476
string args;
7577

76-
if ( test )
78+
if ( this.IsSingleFile )
79+
{
80+
command = "run";
81+
args = "";
82+
}
83+
else if ( test )
7784
{
7885
command = "test";
7986
args = $"--logger \"trx\" --logger \"console;verbosity=minimal\" --results-directory \"{resultsDirectory}\"";
@@ -112,7 +119,7 @@ private bool RunBuildOrTests(
112119
return true;
113120
}
114121

115-
context.Console.WriteMessage( $"Running {(test ? "test" : "build")} as configured in '{testJsonFile}'." );
122+
context.Console.WriteMessage( $"Running `dotnet {command}` as configured in '{testJsonFile}'." );
116123

117124
_ = DotNetHelper.Run(
118125
context,

src/PostSharp.Engineering.BuildTools/Build/Solutions/ManyDotNetSolutions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ void ProcessDirectory( string directory )
183183
{
184184
// Do not process recursively if we find a file we can build.
185185
// The order of processing is significant.
186-
if ( AddFiles( directory, "*.proj", Model.BuildMethod.Build ) || AddFiles( directory, "*.sln" ) || AddFiles( directory, "*.csproj" ) )
186+
if ( AddFiles( directory, "*.proj", Model.BuildMethod.Build )
187+
|| AddFiles( directory, "*.sln" )
188+
|| AddFiles( directory, "*.csproj" )
189+
|| AddFiles( directory, "Program.cs" ) )
187190
{
188191
return;
189192
}

src/PostSharp.Engineering.BuildTools/Utilities/DotNetHelper.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using PostSharp.Engineering.BuildTools.Build;
55
using PostSharp.Engineering.BuildTools.Build.Model;
66
using PostSharp.Engineering.BuildTools.Tools.TeamCity;
7+
using System;
78
using System.Globalization;
89
using System.IO;
910
using System.Text;
@@ -95,8 +96,11 @@ private static string CreateCommandLine(
9596

9697
if ( isRunCommand )
9798
{
98-
// The command `dotnet run SomeProject.csproj` does not work, it requires explicit argument name.
99-
projectPrefix = "--project ";
99+
if ( !Path.GetExtension( projectOrSolution ).Equals( ".cs", StringComparison.OrdinalIgnoreCase ) )
100+
{
101+
// The command `dotnet run SomeProject.csproj` does not work, it requires explicit argument name.
102+
projectPrefix = "--project ";
103+
}
100104

101105
// dotnet run does not support --nologo.
102106
nologo = string.Empty;

0 commit comments

Comments
 (0)