-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCsprojGen.cs
More file actions
49 lines (41 loc) · 1.71 KB
/
Copy pathCsprojGen.cs
File metadata and controls
49 lines (41 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Google.Protobuf;
using SqlcGenCsharp.Drivers;
using System;
using System.Linq;
using File = Plugin.File;
namespace SqlcGenCsharp.Generators;
internal class CsprojGen(DbDriver dbDriver, string outputDirectory, string projectName, string namespaceName)
{
public File GenerateFile()
{
var csprojContents = GetFileContents();
return new File
{
Name = $"{projectName}.csproj",
Contents = ByteString.CopyFromUtf8(csprojContents)
};
}
private string GetFileContents()
{
var optionalNullableProperty = dbDriver.Options.DotnetFramework.IsDotnetCore() ? Environment.NewLine + " <Nullable>enable</Nullable>" : "";
var referenceItems = dbDriver.GetPackageReferences()
.Select(p => $""" <PackageReference Include="{p.Key}" Version="{p.Value}"/>""")
.JoinByNewLine();
return $"""
<!--{Consts.AutoGeneratedComment}-->
<!--Run the following to add the project to the solution:
dotnet sln add {outputDirectory}/{projectName}.csproj
-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>{dbDriver.Options.DotnetFramework.ToName()}</TargetFramework>
<RootNamespace>{namespaceName}</RootNamespace>
<OutputType>Library</OutputType>{optionalNullableProperty}
</PropertyGroup>
<ItemGroup>
{referenceItems}
</ItemGroup>
</Project>
""";
}
}