Skip to content

Commit 66140bc

Browse files
committed
Allow running samples from main solution for debugging
Projects can be added to the main solution and set as the target for roslyn debugging as needed. The new directory targets simulate package referencing and remove the actual package reference that's otherwise used (using solution name to detect standalone vs debugging sources mode).
1 parent 8c93a92 commit 66140bc

9 files changed

Lines changed: 64 additions & 5 deletions

File tree

src/Sample/Common/Product.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Sample;
1+
using StructId;
2+
3+
namespace Sample;
24

35
public record Product(ProductId Id, string Name);
46

src/Sample/ConsoleDb/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using ConsoleDb;
2-
using Dapper;
1+
using Dapper;
32
using Microsoft.Data.Sqlite;
3+
using StructId;
44

55
SQLitePCL.Batteries.Init();
66

src/Sample/Directory.Build.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<Import Project="..\Directory.Build.props" />
3+
4+
<PropertyGroup>
5+
<FromSource>false</FromSource>
6+
<FromSource Condition="$(SolutionName) == 'StructId'">true</FromSource>
7+
</PropertyGroup>
8+
9+
</Project>

src/Sample/Directory.Build.targets

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project>
2+
<Import Project="..\Directory.Build.targets" />
3+
4+
<PropertyGroup>
5+
<AfterMicrosoftNETSdkTargets>$(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)..\StructId.Package\StructId.targets</AfterMicrosoftNETSdkTargets>
6+
</PropertyGroup>
7+
8+
<ItemGroup Condition="$(FromSource)">
9+
<PackageReference Remove="StructId" />
10+
<PackageReference Include="Scriban" Version="5.12.1" GeneratePathProperty="true" />
11+
12+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\StructId.Analyzer\StructId.Analyzer.csproj" OutputItemType="Analyzer" />
13+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\StructId.CodeFix\StructId.CodeFix.csproj" OutputItemType="Analyzer" />
14+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\StructId.Package\StructId.Package.msbuildproj" ReferenceOutputAssembly="false" />
15+
16+
<Analyzer Include="$(PkgScriban)/lib/netstandard2.0/Scriban.dll" Condition="Exists('$(PkgScriban)/lib/netstandard2.0/Scriban.dll')" />
17+
</ItemGroup>
18+
19+
<Target Name="FromSource" Condition="$(FromSource)" BeforeTargets="AddStructId">
20+
<ItemGroup>
21+
<!-- These would be added from the package-relative paths by the StructId.targets -->
22+
<StructIdCompile Include="$(MSBuildThisFileDirectory)..\StructId\*.cs" />
23+
<StructIdTemplates Include="$(MSBuildThisFileDirectory)..\StructId\Templates\*.cs" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<!-- Templates should always be added by buildTransitive targets -->
28+
<StructId Include="@(StructIdTemplates)" Link="StructId\Templates\%(StructIdTemplates.Filename)%(StructIdTemplates.Extension)" />
29+
</ItemGroup>
30+
31+
<ItemGroup Condition="'$(HasStructIdReference)' != 'false'">
32+
<StructId Include="@(StructIdCompile)" Link="StructId\%(StructIdCompile.Filename)%(StructIdCompile.Extension)" />
33+
</ItemGroup>
34+
</Target>
35+
36+
</Project>

src/Sample/MinimalApi/MinimalApi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<RestoreSources>https://api.nuget.org/v3/index.json;$(PackageOutputPath)</RestoreSources>
88
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
9+
<HasStructIdReference>false</HasStructIdReference>
910
</PropertyGroup>
1011

1112
<ItemGroup>

src/Sample/MinimalApi/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Sample;
2+
using StructId;
23

34
var builder = WebApplication.CreateBuilder(args);
45
var app = builder.Build();
@@ -8,6 +9,6 @@
89

910
app.Run();
1011

11-
readonly partial record struct UserId : IStructId<int>;
12+
readonly partial record struct UserId(int Value) : IStructId<int>;
1213

1314
record User(UserId id, string Alias);

src/Sample/MvcWebApp/Controllers/HomeController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Sample;
3+
using StructId;
34

45
namespace MvcWebApplication.Controllers;
56

@@ -24,6 +25,6 @@ public IActionResult GetProduct(ProductId? id)
2425
}
2526
}
2627

27-
public readonly partial record struct UserId : IStructId<Guid>;
28+
public readonly partial record struct UserId : IStructId<Ulid>;
2829

2930
public record User(UserId id, string Alias);

src/Sample/MvcWebApp/MvcWebApp.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<RestoreSources>https://api.nuget.org/v3/index.json;$(PackageOutputPath)</RestoreSources>
88
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
9+
<HasStructIdReference>false</HasStructIdReference>
910
</PropertyGroup>
1011

12+
<ItemGroup>
13+
<PackageReference Include="Ulid" Version="1.3.4" />
14+
</ItemGroup>
15+
1116
<ItemGroup>
1217
<ProjectReference Include="..\Common\Common.csproj" />
1318
</ItemGroup>

src/StructId.Analyzer/Properties/launchSettings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"Roslyn": {
44
"commandName": "DebugRoslynComponent",
55
"targetProject": "..\\StructId.FunctionalTests\\StructId.FunctionalTests.csproj"
6+
},
7+
"MinimalApi": {
8+
"commandName": "DebugRoslynComponent",
9+
"targetProject": "..\\Sample\\MinimalApi\\MinimalApi.csproj"
610
}
711
}
812
}

0 commit comments

Comments
 (0)