Skip to content

Commit acd05d4

Browse files
authored
[minor] Opt out of centralized package management (#339)
* Opt out of centralized package management Current behavior is that builds are failing when a solution uses centralized package management via Directory.Packages.props files. To prevent this behaviour we are opting out of that centralice package management for generated projects. * Add a option to opt into central package management - New Option 'useCentralPackageManagement' - Deactive package management by default * Fix formatting, regenerate examples, and update documentation - Fix formatting issues in CsprojGen and unit tests - Regenerate all examples with useCentralPackageManagement option - Add dotnet-format target to Makefile - Update documentation for the new useCentralPackageManagement option * Regenerate
1 parent 2635255 commit acd05d4

File tree

55 files changed

+119
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+119
-35
lines changed

CodeGenerator/Generators/CsprojGen.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ private string GetFileContents()
2323
{
2424
var optionalNullableProperty = dbDriver.Options.DotnetFramework.IsDotnetCore() ? Environment.NewLine + " <Nullable>enable</Nullable>" : "";
2525
var referenceItems = dbDriver.GetPackageReferences()
26-
.Select(p => $""" <PackageReference Include="{p.Key}" Version="{p.Value}"/>""")
26+
.Select(p => dbDriver.Options.UseCentralPackageManagement
27+
? $""" <PackageReference Include="{p.Key}" />"""
28+
: $""" <PackageReference Include="{p.Key}" Version="{p.Value}"/>""")
2729
.JoinByNewLine();
2830

2931
return $"""
@@ -37,6 +39,7 @@ dotnet sln add {outputDirectory}/{projectName}.csproj
3739
<TargetFramework>{dbDriver.Options.DotnetFramework.ToName()}</TargetFramework>
3840
<RootNamespace>{namespaceName}</RootNamespace>
3941
<OutputType>Library</OutputType>{optionalNullableProperty}
42+
<ManagePackageVersionsCentrally>{dbDriver.Options.UseCentralPackageManagement}</ManagePackageVersionsCentrally>
4043
</PropertyGroup>
4144
4245
<ItemGroup>

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ setup-ci-wasm-plugin:
3939

4040
# Manual
4141
generate-protobuf:
42-
./scripts/generate_protobuf.sh
42+
./scripts/generate_protobuf.sh
43+
44+
dotnet-format:
45+
dotnet format --exclude GeneratedProtobuf --exclude examples

PluginOptions/Options.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public Options(GenerateRequest generateRequest)
2929
if (rawOptions.DebugRequest && generateRequest.Settings.Codegen.Wasm is not null)
3030
throw new ArgumentException("Debug request mode cannot be used with WASM plugin");
3131
DebugRequest = rawOptions.DebugRequest;
32+
33+
UseCentralPackageManagement = rawOptions.UseCentralPackageManagement;
3234
}
3335

3436
public DriverName DriverName { get; }
@@ -49,6 +51,12 @@ public Options(GenerateRequest generateRequest)
4951

5052
public bool DebugRequest { get; }
5153

54+
/// <summary>
55+
/// When true generated code will opt in to central package management.
56+
/// https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management
57+
/// </summary>
58+
public bool UseCentralPackageManagement { get; }
59+
5260
private static readonly Dictionary<string, DriverName> EngineToDriverMapping = new()
5361
{
5462
{ "mysql", DriverName.MySqlConnector },

PluginOptions/RawOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public record RawOptions
2828

2929
[JsonPropertyName("debugRequest")]
3030
public bool DebugRequest { get; init; }
31+
32+
[JsonPropertyName("useCentralPackageManagement")]
33+
public bool UseCentralPackageManagement { get; init; }
3134
}
3235

3336
public class OverrideOption

docs/03_Usage.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Usage
22
## Options
3-
| Option | Possible values | Optional | Info |
4-
|--------------------- |----------------------------------------------------------------------------------------------|----------|------|
5-
| overrideDriverVersion| default:<br/> `2.3.6` for MySqlConnector (mysql)<br/>`8.0.3` for Npgsql (postgresql)<br/>`8.0.10` for Microsoft.Data.Sqlite (sqlite)<br/><br/>values: The desired driver version | Yes | Allows you to override the version of DB driver to be used. |
6-
| targetFramework | default: `net8.0`<br/>values: `netstandard2.0`, `netstandard2.1`, `net8.0` | Yes | Determines the target framework for your generated code, meaning the generated code will be compiled to the specified runtime.<br/>For more information and help deciding on the right value, refer to the [Microsoft .NET Standard documentation](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-1-0). |
7-
| generateCsproj | default: `true`<br/>values: `false`,`true` | Yes | Assists you with the integration of SQLC and csharp by generating a `.csproj` file. This converts the generated output to a .dll, a project that you can easily incorporate into your build process. |
8-
| namespaceName | default: the generated project name | Yes | Allows you to override the namespace name to be different than the project name |
9-
| useDapper | default: `false`<br/>values: `false`,`true` | Yes | Enables Dapper as a thin wrapper for the generated code. For more information, please refer to the [Dapper documentation](https://github.com/DapperLib/Dapper). |
10-
| overrideDapperVersion| default:<br/> `2.1.35`<br/>values: The desired Dapper version | Yes | If `useDapper` is set to `true`, this option allows you to override the version of Dapper to be used. |
11-
| Override | values: A nested override value like [this](#override-option). | Yes | Allows you to override the generated C# data types for specific columns in specific queries. This option accepts a `query_name:column_name` mapping and the overriden data type. | |
3+
4+
| Option | Possible values | Optional | Info |
5+
|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
6+
| overrideDriverVersion | default:<br/> `2.3.6` for MySqlConnector (mysql)<br/>`8.0.3` for Npgsql (postgresql)<br/>`8.0.10` for Microsoft.Data.Sqlite (sqlite)<br/><br/>values: The desired driver version | Yes | Allows you to override the version of DB driver to be used. |
7+
| targetFramework | default: `net8.0`<br/>values: `netstandard2.0`, `netstandard2.1`, `net8.0` | Yes | Determines the target framework for your generated code, meaning the generated code will be compiled to the specified runtime.<br/>For more information and help deciding on the right value, refer to the [Microsoft .NET Standard documentation](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-1-0). |
8+
| generateCsproj | default: `true`<br/>values: `false`,`true` | Yes | Assists you with the integration of SQLC and csharp by generating a `.csproj` file. This converts the generated output to a .dll, a project that you can easily incorporate into your build process. |
9+
| namespaceName | default: the generated project name | Yes | Allows you to override the namespace name to be different than the project name |
10+
| useDapper | default: `false`<br/>values: `false`,`true` | Yes | Enables Dapper as a thin wrapper for the generated code. For more information, please refer to the [Dapper documentation](https://github.com/DapperLib/Dapper). |
11+
| overrideDapperVersion | default:<br/> `2.1.35`<br/>values: The desired Dapper version | Yes | If `useDapper` is set to `true`, this option allows you to override the version of Dapper to be used. |
12+
| Override | values: A nested override value like [this](#override-option). | Yes | Allows you to override the generated C# data types for specific columns in specific queries. This option accepts a `query_name:column_name` mapping and the overriden data type. | |
13+
| useCentralPackageManagement | default: `false`<br/>values: `false`,`true` | Yes | If true, the code is generated to support central package management. |
1214

1315
### Override option
1416
Override for a specific query:

examples/MySqlConnectorDapperExample/MySqlConnectorDapperExample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<RootNamespace>MySqlConnectorDapperExampleGen</RootNamespace>
1010
<OutputType>Library</OutputType>
1111
<Nullable>enable</Nullable>
12+
<ManagePackageVersionsCentrally>False</ManagePackageVersionsCentrally>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

examples/MySqlConnectorDapperExample/request.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3807,5 +3807,5 @@
38073807
}
38083808
],
38093809
"sqlc_version": "v1.30.0",
3810-
"plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0OC4wIiwibmFtZXNwYWNlTmFtZSI6Ik15U3FsQ29ubmVjdG9yRGFwcGVyRXhhbXBsZUdlbiIsInVzZURhcHBlciI6dHJ1ZSwib3ZlcnJpZGVEYXBwZXJWZXJzaW9uIjoiIiwib3ZlcnJpZGVzIjpbeyJjb2x1bW4iOiJHZXRNeXNxbEZ1b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3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiR2V0TXlzcWxGdW5jdGlvbnM6bWF4X3RpbWVzdGFtcCIsImNzaGFycF90eXBlIjp7InR5cGUiOiJEYXRlVGltZSIsIm5vdE51bGwiOnRydWV9fSx7ImNvbHVtbiI6Iio6Y19qc29uX3N0cmluZ19vdmVycmlkZSIsImNzaGFycF90eXBlIjp7InR5cGUiOiJzdHJpbmciLCJub3ROdWxsIjpmYWxzZX19LHsiY29sdW1uIjoiKjpjX3RpbWVzdGFtcF9ub2RhX2luc3RhbnRfb3ZlcnJpZGUiLCJjc2hhcnBfdHlwZSI6eyJ0eXBlIjoiSW5zdGFudCIsIm5vdE51bGwiOmZhbHNlfX1dLCJkZWJ1Z1JlcXVlc3QiOmZhbHNlLCJ1c2VDZW50cmFsUGFja2FnZU1hbmFnZW1lbnQiOmZhbHNlfQ=="
38113811
}
36 Bytes
Binary file not shown.

examples/MySqlConnectorDapperLegacyExample/MySqlConnectorDapperLegacyExample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<TargetFramework>netstandard2.0</TargetFramework>
99
<RootNamespace>MySqlConnectorDapperLegacyExampleGen</RootNamespace>
1010
<OutputType>Library</OutputType>
11+
<ManagePackageVersionsCentrally>False</ManagePackageVersionsCentrally>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

examples/MySqlConnectorDapperLegacyExample/request.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3807,5 +3807,5 @@
38073807
}
38083808
],
38093809
"sqlc_version": "v1.30.0",
3810-
"plugin_options": "eyJvdmVycmlkZURyaXZlclZlcnNpb24iOiIiLCJnZW5lcmF0ZUNzcHJvaiI6dHJ1ZSwidGFyZ2V0RnJhbWV3b3JrIjoibmV0c3RhbmRhcmQyLjAiLCJuYW1lc3BhY2VOYW1lIjoiTXlTcWxDb25uZWN0b3JEYXBwZXJMZWdhY3lFeGFtcGxlR2V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