Skip to content

Commit c80ae95

Browse files
committed
Changed project to push a source generator project and an attributes project
1 parent da0b86a commit c80ae95

File tree

9 files changed

+200
-75
lines changed

9 files changed

+200
-75
lines changed

build/ApplicationBuildConfigs.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Text;
88
using System.Threading.Tasks;
99

10-
public record ProjectPaths(
10+
public record SourceGeneratorProjectPaths(
1111
string ProjectName,
1212
string PathToSln,
1313
string ProjectFolder,
@@ -16,17 +16,17 @@ public record ProjectPaths(
1616
string OutDir,
1717
string NuGetFilePath)
1818
{
19-
public static ProjectPaths LoadFromContext(ICakeContext context, string buildConfiguration, string srcDirectory, string nugetVersion)
19+
public static SourceGeneratorProjectPaths LoadFromContext(ICakeContext context, string buildConfiguration, string srcDirectory, string nugetVersion)
2020
{
2121
var projectName = "PublicInterfaceGenerator";
2222
var pathToSln = srcDirectory + $"/{projectName}.sln";
2323
var projectDir = srcDirectory + $"/{projectName}";
2424
var csProjFile = projectDir + $"/{projectName}.csproj";
2525
var unitTestsProj = srcDirectory + $"/UnitTests/UnitTests.csproj";
26-
var outDir = projectDir + $"/bin/{buildConfiguration}/cake-build-output";
26+
var outDir = projectDir + $"/bin/{buildConfiguration}/cake-build-output/source-generator";
2727
var nugetFilePath = outDir + $"/*{nugetVersion}.nupkg";
2828

29-
return new ProjectPaths(
29+
return new SourceGeneratorProjectPaths(
3030
projectName,
3131
pathToSln,
3232
projectDir,
@@ -36,3 +36,27 @@ public static ProjectPaths LoadFromContext(ICakeContext context, string buildCon
3636
nugetFilePath);
3737
}
3838
};
39+
40+
public record AttributesProjectPaths(
41+
string ProjectName,
42+
string ProjectFolder,
43+
string CsprojFile,
44+
string OutDir,
45+
string NuGetFilePath)
46+
{
47+
public static AttributesProjectPaths LoadFromContext(ICakeContext context, string buildConfiguration, string srcDirectory, string nugetVersion)
48+
{
49+
var projectName = "PublicInterfaceGenerator.Attributes";
50+
var projectDir = srcDirectory + $"/{projectName}";
51+
var csProjFile = projectDir + $"/{projectName}.csproj";
52+
var outDir = projectDir + $"/bin/{buildConfiguration}/cake-build-output/attributes";
53+
var nugetFilePath = outDir + $"/*{nugetVersion}.nupkg";
54+
55+
return new AttributesProjectPaths(
56+
projectName,
57+
projectDir,
58+
csProjFile,
59+
outDir,
60+
nugetFilePath);
61+
}
62+
};

build/Build.csproj

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<Nullable>enable</Nullable>
6-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7-
<LangVersion>preview</LangVersion>
8-
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
9-
</PropertyGroup>
10-
<ItemGroup>
11-
<PackageReference Include="Cake.Frosting" Version="4.0.0" />
12-
</ItemGroup>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<LangVersion>latest</LangVersion>
8+
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<PackageReference Include="Cake.Frosting" Version="5.0.0" />
12+
</ItemGroup>
13+
<PropertyGroup>
14+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
15+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
16+
</PropertyGroup>
17+
<PropertyGroup>
18+
<NuGetAudit>true</NuGetAudit>
19+
<NuGetAuditMode>all</NuGetAuditMode>
20+
<NuGetAuditLevel>low</NuGetAuditLevel>
21+
</PropertyGroup>
1322
</Project>

build/Program.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public class BuildContext : FrostingContext
3131
public string NugetVersion { get; }
3232
public bool PushNuget { get; }
3333
public string NuGetPushToken { get; }
34-
public ProjectPaths ProjectPaths { get; }
34+
public SourceGeneratorProjectPaths SourceGeneratorProjectPaths { get; }
35+
public AttributesProjectPaths AttributesProjectPaths { get; }
3536

3637
public BuildContext(ICakeContext context)
3738
: base(context)
@@ -42,7 +43,8 @@ public BuildContext(ICakeContext context)
4243
NuGetPushToken = LoadParameter(context, "nuGetPushToken");
4344
PushNuget = context.Argument<bool>("pushNuget", false);
4445

45-
ProjectPaths = ProjectPaths.LoadFromContext(context, BuildConfiguration, SrcDirectoryPath, NugetVersion);
46+
SourceGeneratorProjectPaths = SourceGeneratorProjectPaths.LoadFromContext(context, BuildConfiguration, SrcDirectoryPath, NugetVersion);
47+
AttributesProjectPaths = AttributesProjectPaths.LoadFromContext(context, BuildConfiguration, SrcDirectoryPath, NugetVersion);
4648
}
4749

4850
private string LoadParameter(ICakeContext context, string parameterName)
@@ -59,7 +61,8 @@ public override void Run(BuildContext context)
5961
context.Log.Information($"INFO: Current Working Directory: {context.Environment.WorkingDirectory}");
6062

6163
context.Log.Information($"INFO: {nameof(context.SrcDirectoryPath)}: {context.SrcDirectoryPath}");
62-
context.Log.Information($"INFO: {nameof(context.ProjectPaths)}.{nameof(context.ProjectPaths.ProjectName)}: {context.ProjectPaths.ProjectName}");
64+
context.Log.Information($"INFO: {nameof(context.SourceGeneratorProjectPaths)}.{nameof(context.SourceGeneratorProjectPaths.ProjectName)}: {context.SourceGeneratorProjectPaths.ProjectName}");
65+
context.Log.Information($"INFO: {nameof(context.SourceGeneratorProjectPaths)}.{nameof(context.AttributesProjectPaths.ProjectName)}: {context.AttributesProjectPaths.ProjectName}");
6366
}
6467
}
6568

@@ -69,11 +72,12 @@ public sealed class BuildTask : FrostingTask<BuildContext>
6972
{
7073
public override void Run(BuildContext context)
7174
{
72-
context.CleanDirectory(context.ProjectPaths.OutDir);
75+
context.CleanDirectory(context.SourceGeneratorProjectPaths.OutDir);
7376

74-
BuildDotnetApp(context, context.ProjectPaths.PathToSln);
75-
TestDotnetApp(context, context.ProjectPaths.UnitTestProj);
76-
PackNugetPackage(context, context.ProjectPaths.OutDir, context.ProjectPaths.CsprojFile);
77+
BuildDotnetApp(context, context.SourceGeneratorProjectPaths.PathToSln);
78+
TestDotnetApp(context, context.SourceGeneratorProjectPaths.UnitTestProj);
79+
PackNugetPackage(context, context.SourceGeneratorProjectPaths.OutDir, context.SourceGeneratorProjectPaths.CsprojFile);
80+
PackNugetPackage(context, context.AttributesProjectPaths.OutDir, context.AttributesProjectPaths.CsprojFile);
7781
}
7882

7983
private void BuildDotnetApp(BuildContext context, string pathToSln)
@@ -125,11 +129,17 @@ public override void Run(BuildContext context)
125129
return;
126130
}
127131

128-
context.DotNetNuGetPush(context.ProjectPaths.NuGetFilePath, new Cake.Common.Tools.DotNet.NuGet.Push.DotNetNuGetPushSettings
132+
context.DotNetNuGetPush(context.SourceGeneratorProjectPaths.NuGetFilePath, new Cake.Common.Tools.DotNet.NuGet.Push.DotNetNuGetPushSettings
129133
{
130134
Source = "https://api.nuget.org/v3/index.json",
131135
ApiKey = context.NuGetPushToken
132136
});
137+
138+
context.DotNetNuGetPush(context.AttributesProjectPaths.NuGetFilePath, new Cake.Common.Tools.DotNet.NuGet.Push.DotNetNuGetPushSettings
139+
{
140+
Source = "https://api.nuget.org/v3/index.json",
141+
ApiKey = context.NuGetPushToken
142+
});
133143
}
134144
}
135145

code-updater/code-updater-config.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"updatePathOptions": {
3+
"rootDirectory": "../",
4+
"ignorePatterns": [
5+
"/code-updater/",
6+
"/samples/Samples/",
7+
"/.NCrunch_"
8+
]
9+
},
10+
"loggingOptions": {
11+
"logLevel": "Verbose",
12+
"outputFile": "./code-updater-output.log"
13+
},
14+
"cSharpOptions": {
15+
"csProjVersioningOptions": {
16+
"treatWarningsAsErrors": true,
17+
"targetFramework": "net9.0",
18+
"langVersion": "latest"
19+
},
20+
"csProjDotNetAnalyzerOptions": {
21+
"enableNetAnalyzers": true,
22+
"enforceCodeStyleInBuild": true
23+
},
24+
"cSharpStyleOptions": {
25+
"runDotnetFormat": false
26+
},
27+
"nugetOptions": {
28+
"auditOptions": {
29+
"nuGetAudit": true,
30+
"auditMode": "all",
31+
"auditLevel": "low"
32+
},
33+
"updateOptions": {
34+
"updateTopLevelNugetsInCsProj": true,
35+
"updateTopLevelNugetsNotInCsProj": false
36+
}
37+
}
38+
},
39+
"npmOptions": {
40+
"compileOptions": {
41+
"buildCommand": "publish"
42+
}
43+
},
44+
"regexSearchOptions": {
45+
"searches": [
46+
{
47+
"searchRegex": "8\\..+\\.x",
48+
"description": "YAML Dotnet Version"
49+
},
50+
{
51+
"searchRegex": "sdk:8\\.[0-9]",
52+
"description": "Dockerfile sdk version"
53+
},
54+
{
55+
"searchRegex": "aspnet:8\\.[0-9]-",
56+
"description": "Dockerfile ASPNET version"
57+
},
58+
{
59+
"searchRegex": "DOTNET-ISOLATED\\|[0-9]",
60+
"description": "Dotnet Isolated Azure Functions Setting"
61+
}
62+
]
63+
}
64+
}

code-updater/run-code-updater.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$configPath = "$PSScriptRoot/code-updater-config.json"
2+
3+
& "code-updater" --options "$configPath"
Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>Latest</LangVersion>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
8-
<RootNamespace>ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes</RootNamespace>
9-
<AssemblyName>ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes</AssemblyName>
10-
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
11-
<EnableNETAnalyzers>true</EnableNETAnalyzers>
12-
</PropertyGroup>
13-
14-
</Project>
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<RootNamespace>ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes</RootNamespace>
8+
<AssemblyName>ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes</AssemblyName>
9+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
10+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
11+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
12+
</PropertyGroup>
13+
<PropertyGroup>
14+
<IsPackable>true</IsPackable>
15+
<IncludeBuildOutput>true</IncludeBuildOutput>
16+
<DevelopmentDependency>false</DevelopmentDependency>
17+
</PropertyGroup>
18+
<PropertyGroup>
19+
<NuGetAudit>true</NuGetAudit>
20+
<NuGetAuditMode>all</NuGetAuditMode>
21+
<NuGetAuditLevel>low</NuGetAuditLevel>
22+
</PropertyGroup>
23+
</Project>

src/PublicInterfaceGenerator.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples", "..\samples\Sampl
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{C15212B0-08B0-401D-A7BD-B340DE194195}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "..\build\Build.csproj", "{4F1A5CD8-F08F-6B1C-4564-8476E15A785B}"
19+
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CICD", "CICD", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
21+
EndProject
1822
Global
1923
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2024
Debug|Any CPU = Debug|Any CPU
@@ -37,13 +41,18 @@ Global
3741
{C15212B0-08B0-401D-A7BD-B340DE194195}.Debug|Any CPU.Build.0 = Debug|Any CPU
3842
{C15212B0-08B0-401D-A7BD-B340DE194195}.Release|Any CPU.ActiveCfg = Release|Any CPU
3943
{C15212B0-08B0-401D-A7BD-B340DE194195}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{4F1A5CD8-F08F-6B1C-4564-8476E15A785B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{4F1A5CD8-F08F-6B1C-4564-8476E15A785B}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{4F1A5CD8-F08F-6B1C-4564-8476E15A785B}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{4F1A5CD8-F08F-6B1C-4564-8476E15A785B}.Release|Any CPU.Build.0 = Release|Any CPU
4048
EndGlobalSection
4149
GlobalSection(SolutionProperties) = preSolution
4250
HideSolutionNode = FALSE
4351
EndGlobalSection
4452
GlobalSection(NestedProjects) = preSolution
4553
{2CD3B72B-1597-471F-AE24-1D7D6340A324} = {7235A503-C7CD-4028-88F4-15DBD7371471}
4654
{C15212B0-08B0-401D-A7BD-B340DE194195} = {A7E17D8D-F489-4CD6-85DA-03BEE1BDD217}
55+
{4F1A5CD8-F08F-6B1C-4564-8476E15A785B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
4756
EndGlobalSection
4857
GlobalSection(ExtensibilityGlobals) = postSolution
4958
SolutionGuid = {1CC6B6F7-942B-4373-B782-4903EAE16A97}
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<!-- Source generators must target netstandard 2.0 -->
54
<TargetFramework>netstandard2.0</TargetFramework>
6-
75
<!-- Do not include the generator as a lib dependency -->
86
<IncludeBuildOutput>false</IncludeBuildOutput>
9-
10-
<LangVersion>Latest</LangVersion>
7+
<IsPackable>true</IsPackable>
8+
<LangVersion>latest</LangVersion>
119
<ImplicitUsings>enable</ImplicitUsings>
1210
<Nullable>enable</Nullable>
1311
<RootNamespace>ProgrammerAl.SourceGenerators.PublicInterfaceGenerator</RootNamespace>
@@ -16,8 +14,8 @@
1614
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1715
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1816
<PackageReadmeFile>README.md</PackageReadmeFile>
17+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1918
</PropertyGroup>
20-
2119
<PropertyGroup>
2220
<Version>0.1.0</Version>
2321
<Title>Public Interface Generator</Title>
@@ -31,28 +29,23 @@
3129
<!--Mark the nuget as a dev dependency, so any projects using this nuget don't auto pull in this project-->
3230
<DevelopmentDependency>true</DevelopmentDependency>
3331
</PropertyGroup>
34-
3532
<ItemGroup>
36-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
37-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" />
33+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
34+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" PrivateAssets="all" />
3835
</ItemGroup>
39-
40-
<!-- Reference the attributes from the generator to compile against them -->
41-
<!-- Ensure we specify PrivateAssets so the NuGet doesn't have any dependencies -->
42-
<ItemGroup>
43-
<ProjectReference Include="..\PublicInterfaceGenerator.Attributes\PublicInterfaceGenerator.Attributes.csproj" PrivateAssets="All" />
36+
<!-- Reference the attributes from the generator to compile against them -->
37+
<!-- Ensure we specify PrivateAssets so the NuGet doesn't have any dependencies -->
38+
<ItemGroup>
39+
<ProjectReference Include="..\PublicInterfaceGenerator.Attributes\PublicInterfaceGenerator.Attributes.csproj" PrivateAssets="All" />
4440
</ItemGroup>
45-
4641
<ItemGroup>
4742
<!-- Package the generator in the analyzer directory of the nuget package -->
4843
<None Include="$(OutputPath)/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
49-
50-
<!-- Pack the attributes dll in the analyzers/dotnet/cs path so the source generator can use it -->
51-
<None Include="$(OutputPath)/ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
52-
53-
<!-- Pack the attributes dll in the lib\netstandard2.0 path so the library consuming this nuget can use it -->
54-
<None Include="$(OutputPath)/ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes.dll" Pack="true" PackagePath="lib/netstandard2.0" Visible="true" />
55-
5644
<None Include="../../README.md" Pack="true" PackagePath="/" />
5745
</ItemGroup>
58-
</Project>
46+
<PropertyGroup>
47+
<NuGetAudit>true</NuGetAudit>
48+
<NuGetAuditMode>all</NuGetAuditMode>
49+
<NuGetAuditLevel>low</NuGetAuditLevel>
50+
</PropertyGroup>
51+
</Project>

0 commit comments

Comments
 (0)