Skip to content

Commit 8d246cb

Browse files
gfraiteurclaude
andcommitted
Add WSL support via Product.AddWslSupport property.
When AddWslSupport is enabled, the build system now generates: - .wsl.g.props files with WSL-formatted paths (/mnt/c/...) - nuget.wsl.config with WSL-formatted package source paths - Platform-specific conditional imports in Versions.g.props Also add ContainerHostKind.Wsl enum value and corresponding build agent type. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent aa80f19 commit 8d246cb

File tree

8 files changed

+1427
-1294
lines changed

8 files changed

+1427
-1294
lines changed

eng/AutoUpdatedVersions.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<Project>
2-
<PropertyGroup>
3-
<PostSharpEngineeringReleaseVersion>2023.2.309</PostSharpEngineeringReleaseVersion>
4-
<PostSharpEngineeringReleaseMainVersion>2023.2.309</PostSharpEngineeringReleaseMainVersion>
5-
</PropertyGroup>
1+
<Project>
2+
<PropertyGroup>
3+
<PostSharpEngineeringReleaseVersion>2023.2.309</PostSharpEngineeringReleaseVersion>
4+
<PostSharpEngineeringReleaseMainVersion>2023.2.309</PostSharpEngineeringReleaseMainVersion>
5+
</PropertyGroup>
66
</Project>
Lines changed: 114 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,115 @@
1-
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2-
3-
using Microsoft.Build.Evaluation;
4-
using PostSharp.Engineering.BuildTools.Build.MSBuild;
5-
using PostSharp.Engineering.BuildTools.Dependencies.Model;
6-
using PostSharp.Engineering.BuildTools.Utilities;
7-
using System;
8-
using System.IO;
9-
using System.Linq;
10-
11-
namespace PostSharp.Engineering.BuildTools.Build.Files;
12-
13-
/// <summary>
14-
/// Reads and writes the <c>Versions.g.props</c> file.
15-
/// </summary>
16-
internal static class ConfigurationNeutralVersionFile
17-
{
18-
private static string GetPath( BuildContext context )
19-
{
20-
var product = context.Product;
21-
22-
return Path.Combine( context.RepoDirectory, product.EngineeringDirectory, "Versions.g.props" );
23-
}
24-
25-
internal static BuildConfiguration? ReadDefaultConfiguration( BuildContext context )
26-
{
27-
var path = GetPath( context );
28-
29-
if ( !File.Exists( path ) )
30-
{
31-
return null;
32-
}
33-
34-
var versionFile = Project.FromFile( path, MSBuildLoadOptions.IgnoreImportErrors );
35-
36-
var configuration = versionFile.Properties.SingleOrDefault( p => p.Name == "EngineeringConfiguration" )
37-
?.UnevaluatedValue;
38-
39-
if ( configuration == null )
40-
{
41-
return null;
42-
}
43-
44-
// Note that the version suffix is not copied from the dependency, only the main version.
45-
46-
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
47-
48-
return Enum.Parse<BuildConfiguration>( configuration );
49-
}
50-
51-
public static void Write(
52-
BuildContext context,
53-
CommonCommandSettings settings,
54-
BuildConfiguration buildConfiguration )
55-
{
56-
var configurationNeutralVersionsFilePath = GetPath( context );
57-
var configurationSpecificVersionFilePath = DependenciesConfigurationFile.GetPath( context, settings, buildConfiguration );
58-
59-
context.Console.WriteMessage( $"Writing '{configurationNeutralVersionsFilePath}'." );
60-
61-
TextFileHelper.WriteIfDifferent(
62-
configurationNeutralVersionsFilePath,
63-
$@"
64-
<!-- File generated by PostSharp.Engineering {VersionHelper.EngineeringVersion}, method {nameof(ConfigurationNeutralVersionFile)}.{nameof(Write)}. -->
65-
<Project>
66-
<PropertyGroup>
67-
<EngineeringConfiguration>{buildConfiguration}</EngineeringConfiguration>
68-
</PropertyGroup>
69-
<Import Project=""{configurationSpecificVersionFilePath}"" Condition=""'$(DoNotLoadGeneratedVersionFiles)'!='True' AND Exists('{configurationSpecificVersionFilePath}')""/>
70-
</Project>
71-
",
72-
context );
73-
}
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Microsoft.Build.Evaluation;
4+
using PostSharp.Engineering.BuildTools.Build.MSBuild;
5+
using PostSharp.Engineering.BuildTools.Dependencies.Model;
6+
using PostSharp.Engineering.BuildTools.Utilities;
7+
using System;
8+
using System.IO;
9+
using System.Linq;
10+
11+
namespace PostSharp.Engineering.BuildTools.Build.Files;
12+
13+
/// <summary>
14+
/// Reads and writes the <c>Versions.g.props</c> file.
15+
/// </summary>
16+
internal static class ConfigurationNeutralVersionFile
17+
{
18+
private static string GetPath( BuildContext context )
19+
{
20+
var product = context.Product;
21+
22+
return Path.Combine( context.RepoDirectory, product.EngineeringDirectory, "Versions.g.props" );
23+
}
24+
25+
internal static BuildConfiguration? ReadDefaultConfiguration( BuildContext context )
26+
{
27+
var path = GetPath( context );
28+
29+
if ( !File.Exists( path ) )
30+
{
31+
return null;
32+
}
33+
34+
var versionFile = Project.FromFile( path, MSBuildLoadOptions.IgnoreImportErrors );
35+
36+
var configuration = versionFile.Properties.SingleOrDefault( p => p.Name == "EngineeringConfiguration" )
37+
?.UnevaluatedValue;
38+
39+
if ( configuration == null )
40+
{
41+
return null;
42+
}
43+
44+
// Note that the version suffix is not copied from the dependency, only the main version.
45+
46+
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
47+
48+
return Enum.Parse<BuildConfiguration>( configuration );
49+
}
50+
51+
private static string ConvertToWslPath( string path )
52+
{
53+
// Convert Windows path to WSL: C:\path -> /mnt/c/path
54+
if ( path is [_, ':', _, ..] && (path[2] == '\\' || path[2] == '/') )
55+
{
56+
var drive = char.ToLower( path[0], System.Globalization.CultureInfo.InvariantCulture );
57+
var remainder = path.Substring( 2 ).Replace( "\\", "/", StringComparison.Ordinal );
58+
59+
return $"/mnt/{drive}{remainder}";
60+
}
61+
62+
return path;
63+
}
64+
65+
public static void Write(
66+
BuildContext context,
67+
CommonCommandSettings settings,
68+
BuildConfiguration buildConfiguration )
69+
{
70+
var configurationNeutralVersionsFilePath = GetPath( context );
71+
var configurationSpecificVersionFilePath = DependenciesConfigurationFile.GetPath( context, settings, buildConfiguration );
72+
73+
context.Console.WriteMessage( $"Writing '{configurationNeutralVersionsFilePath}'." );
74+
75+
string content;
76+
77+
if ( context.Product.AddWslSupport )
78+
{
79+
var wslVersionFilePath = DependenciesConfigurationFile.GetWslPath( context, settings, buildConfiguration );
80+
81+
// Transform WSL path to WSL format for use in the Import element
82+
var wslVersionFilePathInWslFormat = ConvertToWslPath( wslVersionFilePath );
83+
84+
content = $@"
85+
<!-- File generated by PostSharp.Engineering {VersionHelper.EngineeringVersion}, method {nameof(ConfigurationNeutralVersionFile)}.{nameof(Write)}. -->
86+
<Project>
87+
<PropertyGroup>
88+
<EngineeringConfiguration>{buildConfiguration}</EngineeringConfiguration>
89+
</PropertyGroup>
90+
<!-- Load WSL version if running under Unix/WSL -->
91+
<Import Project=""{wslVersionFilePathInWslFormat}"" Condition=""'$(DoNotLoadGeneratedVersionFiles)'!='True' AND '$([MSBuild]::IsOSPlatform(Linux))' == 'true' AND Exists('{wslVersionFilePathInWslFormat}')""/>
92+
<!-- Load Windows version if running under Windows -->
93+
<Import Project=""{configurationSpecificVersionFilePath}"" Condition=""'$(DoNotLoadGeneratedVersionFiles)'!='True' AND '$([MSBuild]::IsOSPlatform(Windows))' == 'true' AND Exists('{configurationSpecificVersionFilePath}')""/>
94+
</Project>
95+
";
96+
}
97+
else
98+
{
99+
content = $@"
100+
<!-- File generated by PostSharp.Engineering {VersionHelper.EngineeringVersion}, method {nameof(ConfigurationNeutralVersionFile)}.{nameof(Write)}. -->
101+
<Project>
102+
<PropertyGroup>
103+
<EngineeringConfiguration>{buildConfiguration}</EngineeringConfiguration>
104+
</PropertyGroup>
105+
<Import Project=""{configurationSpecificVersionFilePath}"" Condition=""'$(DoNotLoadGeneratedVersionFiles)'!='True' AND Exists('{configurationSpecificVersionFilePath}')""/>
106+
</Project>
107+
";
108+
}
109+
110+
TextFileHelper.WriteIfDifferent(
111+
configurationNeutralVersionsFilePath,
112+
content,
113+
context );
114+
}
74115
}

0 commit comments

Comments
 (0)