From afbf2967ffb02379dc82e81ba20a5d7a6657e87f Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Sun, 22 Dec 2024 21:08:03 -0300 Subject: [PATCH] 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). --- src/Sample/Common/Product.cs | 4 ++- src/Sample/ConsoleDb/Program.cs | 4 +-- src/Sample/Directory.Build.props | 9 +++++ src/Sample/Directory.Build.targets | 36 +++++++++++++++++++ src/Sample/MinimalApi/MinimalApi.csproj | 1 + src/Sample/MinimalApi/Program.cs | 3 +- .../MvcWebApp/Controllers/HomeController.cs | 3 +- src/Sample/MvcWebApp/MvcWebApp.csproj | 5 +++ .../Properties/launchSettings.json | 4 +++ 9 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 src/Sample/Directory.Build.props create mode 100644 src/Sample/Directory.Build.targets diff --git a/src/Sample/Common/Product.cs b/src/Sample/Common/Product.cs index 18ba1e5..6eec2d4 100644 --- a/src/Sample/Common/Product.cs +++ b/src/Sample/Common/Product.cs @@ -1,4 +1,6 @@ -namespace Sample; +using StructId; + +namespace Sample; public record Product(ProductId Id, string Name); diff --git a/src/Sample/ConsoleDb/Program.cs b/src/Sample/ConsoleDb/Program.cs index a50b83e..34ff773 100644 --- a/src/Sample/ConsoleDb/Program.cs +++ b/src/Sample/ConsoleDb/Program.cs @@ -1,6 +1,6 @@ -using ConsoleDb; -using Dapper; +using Dapper; using Microsoft.Data.Sqlite; +using StructId; SQLitePCL.Batteries.Init(); diff --git a/src/Sample/Directory.Build.props b/src/Sample/Directory.Build.props new file mode 100644 index 0000000..adc22b9 --- /dev/null +++ b/src/Sample/Directory.Build.props @@ -0,0 +1,9 @@ + + + + + false + true + + + diff --git a/src/Sample/Directory.Build.targets b/src/Sample/Directory.Build.targets new file mode 100644 index 0000000..1b4e8e2 --- /dev/null +++ b/src/Sample/Directory.Build.targets @@ -0,0 +1,36 @@ + + + + + $(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)..\StructId.Package\StructId.targets + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Sample/MinimalApi/MinimalApi.csproj b/src/Sample/MinimalApi/MinimalApi.csproj index fe77ac5..0a2281e 100644 --- a/src/Sample/MinimalApi/MinimalApi.csproj +++ b/src/Sample/MinimalApi/MinimalApi.csproj @@ -6,6 +6,7 @@ enable https://api.nuget.org/v3/index.json;$(PackageOutputPath) true + false diff --git a/src/Sample/MinimalApi/Program.cs b/src/Sample/MinimalApi/Program.cs index 88ad597..c1ad909 100644 --- a/src/Sample/MinimalApi/Program.cs +++ b/src/Sample/MinimalApi/Program.cs @@ -1,4 +1,5 @@ using Sample; +using StructId; var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); @@ -8,6 +9,6 @@ app.Run(); -readonly partial record struct UserId : IStructId; +readonly partial record struct UserId(int Value) : IStructId; record User(UserId id, string Alias); \ No newline at end of file diff --git a/src/Sample/MvcWebApp/Controllers/HomeController.cs b/src/Sample/MvcWebApp/Controllers/HomeController.cs index abd538a..fe49308 100644 --- a/src/Sample/MvcWebApp/Controllers/HomeController.cs +++ b/src/Sample/MvcWebApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Sample; +using StructId; namespace MvcWebApplication.Controllers; @@ -24,6 +25,6 @@ public IActionResult GetProduct(ProductId? id) } } -public readonly partial record struct UserId : IStructId; +public readonly partial record struct UserId : IStructId; public record User(UserId id, string Alias); \ No newline at end of file diff --git a/src/Sample/MvcWebApp/MvcWebApp.csproj b/src/Sample/MvcWebApp/MvcWebApp.csproj index fe77ac5..25d835a 100644 --- a/src/Sample/MvcWebApp/MvcWebApp.csproj +++ b/src/Sample/MvcWebApp/MvcWebApp.csproj @@ -6,8 +6,13 @@ enable https://api.nuget.org/v3/index.json;$(PackageOutputPath) true + false + + + + diff --git a/src/StructId.Analyzer/Properties/launchSettings.json b/src/StructId.Analyzer/Properties/launchSettings.json index 98ff4e5..dabd937 100644 --- a/src/StructId.Analyzer/Properties/launchSettings.json +++ b/src/StructId.Analyzer/Properties/launchSettings.json @@ -3,6 +3,10 @@ "Roslyn": { "commandName": "DebugRoslynComponent", "targetProject": "..\\StructId.FunctionalTests\\StructId.FunctionalTests.csproj" + }, + "MinimalApi": { + "commandName": "DebugRoslynComponent", + "targetProject": "..\\Sample\\MinimalApi\\MinimalApi.csproj" } } } \ No newline at end of file