Skip to content

Commit

Permalink
feat(csharp): Let users customize MSBuild properties using props file (
Browse files Browse the repository at this point in the history
…#5130)

Let users customize MSBuild properties using props file
  • Loading branch information
Swimburger authored Nov 8, 2024
1 parent d0fb1b4 commit 3ad58f4
Show file tree
Hide file tree
Showing 299 changed files with 3,947 additions and 3 deletions.
3 changes: 2 additions & 1 deletion generators/csharp/codegen/src/AsIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export enum AsIsFiles {
TemplateTestCsProj = "Template.Test.csproj",
TemplateTestClientCs = "TemplateTestClient.cs",
UsingCs = "Using.cs",
Extensions = "Extensions.cs"
Extensions = "Extensions.cs",
CustomProps = "Custom.props.Template"
}
20 changes: 20 additions & 0 deletions generators/csharp/codegen/src/asIs/Custom.props.Template
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
Configure additional MSBuild properties for your project in this file:
- Step 1: Add this file to your .fernignore file to ensure it is not overwritten.
- Step 2: Modify this file to your liking.
-->
<Project Sdk="Microsoft.NET.Sdk">
<!--
<PropertyGroup>
<Title>Contoso SDK</Title>
<Authors>Contoso</Authors>
<Company>Contoso</Company>
<AssemblyName>Contoso.Sdk</AssemblyName>
<AssemblyTitle>Contoso SDK</AssemblyTitle>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\icon.png" Pack="true" PackagePath="" />
</ItemGroup>
-->
</Project>
13 changes: 12 additions & 1 deletion generators/csharp/codegen/src/project/CsharpProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class CsharpProject extends AbstractProject<AbstractCsharpGeneratorContex
);
const protobufSourceFilePaths = await this.sourceFetcher.copyProtobufSources(absolutePathToProtoDirectory);
const csproj = new CsProj({
name: this.name,
license: this.context.config.license,
githubUrl: this.context.config.output?.mode._visit({
downloadFiles: () => undefined,
Expand All @@ -198,6 +199,12 @@ export class CsharpProject extends AbstractProject<AbstractCsharpGeneratorContex
join(absolutePathToProjectDirectory, RelativeFilePath.of(`${this.name}.csproj`)),
templateCsProjContents
);

await writeFile(
join(absolutePathToProjectDirectory, RelativeFilePath.of(`${this.name}.Custom.props`)),
(await readFile(getAsIsFilepath(AsIsFiles.CustomProps))).toString()
);

await loggingExeca(this.context.logger, "dotnet", ["sln", "add", `${this.name}/${this.name}.csproj`], {
doNotPipeOutput: true,
cwd: absolutePathToSrcDirectory
Expand Down Expand Up @@ -435,6 +442,7 @@ class CsharpProjectFilepaths {

declare namespace CsProj {
interface Args {
name: string;
version?: string;
license?: FernGeneratorExec.LicenseConfig;
githubUrl?: string;
Expand All @@ -446,13 +454,15 @@ declare namespace CsProj {
const FOUR_SPACES = " ";

class CsProj {
private name: string;
private license: FernGeneratorExec.LicenseConfig | undefined;
private githubUrl: string | undefined;
private packageId: string | undefined;
private context: AbstractCsharpGeneratorContext<BaseCsharpCustomConfigSchema>;
private protobufSourceFilePaths: RelativeFilePath[];

public constructor({ license, githubUrl, context, protobufSourceFilePaths }: CsProj.Args) {
public constructor({ name, license, githubUrl, context, protobufSourceFilePaths }: CsProj.Args) {
this.name = name;
this.license = license;
this.githubUrl = githubUrl;
this.context = context;
Expand Down Expand Up @@ -501,6 +511,7 @@ ${this.getAdditionalItemGroups().join(`\n${FOUR_SPACES}`)}
</AssemblyAttribute>
</ItemGroup>
<Import Project="${this.name}.Custom.props" />
</Project>
`;
}
Expand Down
7 changes: 6 additions & 1 deletion generators/csharp/sdk/src/SdkCustomConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export const SdkCustomConfigSchema = z.strictObject({
"root-namespace-for-core-classes": z.boolean().optional(),
"pascal-case-environments": z.boolean().optional(),
"generate-error-types": z.boolean().optional(),
"extra-dependencies": z.record(z.string()).optional(),
"extra-dependencies": z
.record(z.string())
.optional()
.describe(
"(Deprecated) The extra dependencies to add into the csproj file. Use the [ProjectName].Custom.props to configure additional dependencies instead."
),
"read-only-memory-types": z.optional(z.array(z.string())),
"experimental-enable-forward-compatible-enums": z.boolean().optional(),
"generate-mock-server-tests": z.boolean().optional(),
Expand Down
6 changes: 6 additions & 0 deletions generators/csharp/sdk/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# The C# SDK now uses forward-compatible enums which are not compatible with the previously generated enums.
# Set `enable-forward-compatible-enums` to `false` in the configuration to generate the old enums.
# irVersion: 53
- version: 1.9.3
createdAt: "2024-11-07"
changelogEntry:
- type: feat
summary: Generate a ProjectName.Custom.props file for you to configure any MSBuild properties for your project.
irVersion: 53
- version: 1.9.2-alpha.0
createdAt: "2024-11-07"
changelogEntry:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions seed/csharp-model/alias/src/SeedAlias/SeedAlias.Custom.props

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/csharp-model/alias/src/SeedAlias/SeedAlias.csproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions seed/csharp-model/bytes/src/SeedBytes/SeedBytes.Custom.props

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/csharp-model/bytes/src/SeedBytes/SeedBytes.csproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ad58f4

Please sign in to comment.