Skip to content

Commit ade1cba

Browse files
add dotnet build parameter to set cadl options (#3166)
* add dotnet build parameter to set cadl options * update the refresh azure-sdk-for-net doc * update doc * Update readme.md Co-authored-by: Dapeng Zhang <[email protected]> * update doc title --------- Co-authored-by: Dapeng Zhang <[email protected]>
1 parent b74272a commit ade1cba

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

readme.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ ___
1010

1111
# C# code generator for AutoRest V3
1212

13-
- [Prerequisites](#prerequisites)
14-
- [Build](#build)
15-
- [Test](#test)
16-
- [Use in azure-sdk-net repo](#use-in-azure-sdk-net-repo)
17-
- [Use outside of the azure-sdk-net repo](#use-outside-of-the-azure-sdk-net-repo)
18-
- [Customizing the generated code](#customizing-the-generated-code)
13+
- [C# code generator for AutoRest V3](#c-code-generator-for-autorest-v3)
14+
- [Prerequisites](#prerequisites)
15+
- [Build](#build)
16+
- [Test](#test)
17+
- [Testing Details](#testing-details)
18+
- [Validate generator changes against Azure SDK before merging your autorest.csharp PR](#validate-generator-changes-against-azure-sdk-before-merging-your-autorestcsharp-pr)
19+
- [Use in `azure-sdk-for-net` repo](#use-in-azure-sdk-for-net-repo)
20+
- [PR Integration with Azure SDK Repository](#pr-integration-with-azure-sdk-repository)
21+
- [Use outside of the `azure-sdk-for-net` repo](#use-outside-of-the-azure-sdk-for-net-repo)
22+
- [Debugging](#debugging)
23+
- [Debugging transforms](#debugging-transforms)
24+
- [Customizing the generated code](#customizing-the-generated-code)
1925
- [Make a model internal](#make-a-model-internal)
2026
- [Rename a model class](#rename-a-model-class)
2127
- [Change a model or client namespace](#change-a-model-or-client-namespace)
@@ -36,7 +42,7 @@ ___
3642
- [Change operation accessibility in bulk](#change-operation-accessibility-in-bulk)
3743
- [Exclude models from namespace](#exclude-models-from-namespace)
3844
- [Extending a model with additional constructors](#extending-a-model-with-additional-constructors)
39-
- [Management plane concepts and configurations](#management-plane-concepts-and-configurations)
45+
- [Management plane concepts and configurations](#management-plane-concepts-and-configurations)
4046

4147
<!-- /TOC -->
4248

@@ -98,17 +104,11 @@ When the automatic PR is created for azure-sdk-for-net if there are any issues f
98104
}
99105
```
100106
4. Locate the `dll` file generated for the generator, usually it could be found `autorest.csharp` repository in this directory: `artifacts\bin\AutoRest.CSharp\Debug\net6.0\AutoRest.CSharp.dll`
101-
5. Go to [this file](https://github.com/Azure/azure-sdk-for-net/blob/285cbdc343f01774b2b33e758662222bc8a3a33b/eng/common/scripts/Cadl-Project-Generate.ps1#L80) in your local `azure-sdk-for-net` repository, and change it like this by appending a new option to the emitter invocation:
102-
```diff
103-
-$cadlCompileCommand = "npx cadl compile $mainCadlFile --emit $emitterName$emitterAdditionalOptions"
104-
+$cadlCompileCommand = "npx cadl compile $mainCadlFile --emit $emitterName$emitterAdditionalOptions --option @azure-tools/cadl-csharp.csharpGeneratorPath=/absolute/path/to/artifacts/bin/AutoRest.CSharp/Debug/net6.0/AutoRest.CSharp.dll"
105-
```
106-
This process right now is complicated, and the improvement is tracking in [this issue](https://github.com/Azure/azure-sdk-for-net/issues/34357).
107107
- At this point there are several ways to generate but the idea is to generate and test all projects that will be affected by your PR. There are tools such as [this](https://github.com/ArcturusZhang/Regen) which are written to handle specific cases. If you are unsure you should run against all projects to be safe.
108108

109109
To regen and test everything in azure-sdk-for-net after you have updated to use your new local build do the following:
110110

111-
- First generate all projects in the repo by executing `dotnet build [RepoRoot]/eng/service.proj /t:GenerateCode`
111+
- First generate all projects in the repo by executing `dotnet build [RepoRoot]/eng/service.proj /t:GenerateCode`. If your generator PR needs to apply to typespec/cadl projects, or your generator PR changes anything in our emitter (the `src\CADL.Extension\Emitter.Csharp` project), you will need to run `dotnet build [RepoRoot]/eng/service.proj /t:GenerateCode /p:CadlAdditionalOptions="csharpGeneratorPath=/absolute/path/to/artifacts/bin/AutoRest.CSharp/Debug/net6.0/AutoRest.CSharp.dll`.
112112
- Next we want to at minimum run the tests against the new generated code by using `dotnet test [RepoRoot]/eng/service.proj --filter "(TestCategory!=Manually) & (TestCategory!=Live)"`
113113
- For non GA libraries there could be API changes so we want to run the Export-API script with no parameters which will update any projects that now have an API change `[RepoRoot]\eng\scripts\Export-API.ps1`
114114
- Finally it is very possible that we will need to make test case changes or snippet changes especially for non GA libraries which have expected changes. All of these should be made in the branch and included in the PR to demonstrate all resulting changes from the autorest.csharp PR.
@@ -155,7 +155,7 @@ The generator is shipped as a NuGet package.
155155
This way, every binding stays in lockstep with the current generator
156156

157157

158-
## Use outside of the `azure-sdk-net` repo
158+
## Use outside of the `azure-sdk-for-net` repo
159159

160160
Use below command to generate code:
161161

src/AutoRest.CSharp/build/CodeGeneration.targets

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
use the following command line (remove the space between minus minus): dotnet msbuild /t:GenerateCode /p:AutoRestAdditionalParameters="- -interactive"
1717
-->
1818

19+
<!--
20+
<CadlAdditionalOptions></CadlAdditionalOptions>
21+
22+
Allows passing additional cadl command line arguments, for example to run special emitter
23+
use the following command line: dotnet msbuild /t:GenerateCode /p:CadlAdditionalOptions="csharpGeneratorPath=/absolute/path/to/artifacts/bin/AutoRest.CSharp/Debug/net6.0/AutoRest.CSharp.dll"
24+
-->
25+
1926
<IncludeAzureCoreSharedCode Condition="'$(IncludeAzureCoreSharedCode)' == ''">true</IncludeAzureCoreSharedCode>
2027
<AzureCoreSharedCodeDirectory Condition="'$(AzureCoreSharedCodeDirectory)' == ''">$(MSBuildThisFileDirectory)../content/Azure.Core.Shared/</AzureCoreSharedCodeDirectory>
2128
<AutoRestSharedCodeDirectory>$(MSBuildThisFileDirectory)../content/Generator.Shared/</AutoRestSharedCodeDirectory>
@@ -46,7 +53,7 @@
4653

4754
<Target Name="_GenerateCodeForCadl" Condition="'$(_GenerateCode)' == 'true' AND '$(CadlInput)' != ''" >
4855
<Exec Command="$(PowerShellExe) -NoProfile -NonInteractive -executionpolicy Unrestricted -File $(CadlProjectSyncScriptPath) $(MSBuildProjectDirectory)/.."/>
49-
<Exec Command="$(PowerShellExe) -NoProfile -NonInteractive -executionpolicy Unrestricted -File $(CadlProjectGenerateScriptPath) $(MSBuildProjectDirectory)/.."/>
56+
<Exec Command="$(PowerShellExe) -NoProfile -NonInteractive -executionpolicy Unrestricted -File $(CadlProjectGenerateScriptPath) $(MSBuildProjectDirectory)/.. $(CadlAdditionalOptions)"/>
5057
</Target>
5158

5259
<Target Name="GenerateTest" Condition="'$(AutoRestTestsInput)' != ''">

0 commit comments

Comments
 (0)