Skip to content

Commit af7c6e1

Browse files
Add generateCode target (#50167)
1 parent 5b74ccd commit af7c6e1

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

eng/Directory.Build.Common.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<!-- Client in this context is any library that is following the new Azure SDK guidelines -->
1414
<IsGeneratorLibrary Condition="'$(IsGeneratorLibrary)' == '' and $(MSBuildProjectName.StartsWith('Azure.Generator'))">true</IsGeneratorLibrary>
1515
<IsClientLibrary Condition="'$(IsClientLibrary)' == '' and $(MSBuildProjectName.StartsWith('Azure.'))">true</IsClientLibrary>
16+
<IncludeAutorestDependency Condition="'$(IncludeAutorestDependency)' != 'false' and '$(IsClientLibrary)' == 'true'">true</IncludeAutorestDependency>
1617
<IsFunctionsLibrary Condition="'$(IsFunctionsLibrary)' == '' and $(MSBuildProjectName.StartsWith('Microsoft.Azure.WebJobs.Extensions.'))">true</IsFunctionsLibrary>
1718
<IsSourceGenerator Condition="'$(IsSourceGenerator)' == '' and $(MSBuildProjectName.EndsWith('.SourceGeneration'))">true</IsSourceGenerator>
1819

eng/Directory.Build.Common.targets

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
<!-- Add Client SDK Tools -->
9191
<ItemGroup>
92-
<PackageReference Condition="'$(IsClientLibrary)' == 'true'" Include="Microsoft.Azure.AutoRest.CSharp" PrivateAssets="All" />
92+
<PackageReference Condition="'$(IncludeAutorestDependency)' == 'true'" Include="Microsoft.Azure.AutoRest.CSharp" PrivateAssets="All" />
9393

9494
<PackageReference Condition="'$(GenerateAPIListing)' == 'true'" Include="Microsoft.DotNet.GenAPI" PrivateAssets="All" />
9595

@@ -435,6 +435,27 @@
435435
<ProjectsToInclude Include="$(_ProjectName)" />
436436
</ItemGroup>
437437
</Target>
438+
439+
<PropertyGroup>
440+
<TypeSpecInput Condition="Exists('$(MSBuildProjectDirectory)/../tsp-location.yaml') and $(MSBuildProjectDirectory.EndsWith('src'))">$(MSBuildProjectDirectory)/../tsp-location.yaml</TypeSpecInput>
441+
<_TypeSpecProjectGenerateCommand>npx --no-install --package=@azure-tools/typespec-client-generator-cli --yes tsp-client generate --no-prompt --output-dir $(MSBuildProjectDirectory)/../</_TypeSpecProjectGenerateCommand>
442+
<_TypeSpecProjectSyncAndGenerateCommand>npx --no-install --package=@azure-tools/typespec-client-generator-cli --yes tsp-client update --no-prompt --output-dir $(MSBuildProjectDirectory)/../</_TypeSpecProjectSyncAndGenerateCommand>
443+
<_SaveInputs Condition="'$(SaveInputs)' == 'true'">--save-inputs</_SaveInputs>
444+
<!-- Here we append the generate-test-project configuration to TypespecAdditionalOptions if it is specified -->
445+
<TypespecAdditionalOptions Condition="'$(GenerateTestProject)' != '' AND '$(TypespecAdditionalOptions)' != ''">$(TypespecAdditionalOptions)%3Bgenerate-test-project=true</TypespecAdditionalOptions>
446+
<TypespecAdditionalOptions Condition="'$(GenerateTestProject)' != '' AND '$(TypespecAdditionalOptions)' == ''">generate-test-project=true</TypespecAdditionalOptions>
447+
<_TypespecAdditionalOptions Condition="'$(TypespecAdditionalOptions)' != ''">--emitter-options "$(TypespecAdditionalOptions)"</_TypespecAdditionalOptions>
448+
<_LocalSpecRepo Condition="'$(LocalSpecRepo)' != ''">--local-spec-repo $(LocalSpecRepo)</_LocalSpecRepo>
449+
</PropertyGroup>
450+
451+
<!-- For projects using the new TypeSpec generator, we don't include the Autorest dependency which pulls in the GenerateCode target.
452+
So we need to add it here. -->
453+
<Target Name="GenerateCode" Condition="'$(IncludeAutorestDependency)' != 'true' AND '$(TypeSpecInput)' != ''">
454+
<Error Text="You used skipped sync but didn't have the TempTypeSpecFiles in your project directory. Please run 'dotnet build /t:GenerateCode /p:SaveInputs=true' without SkipSync first at least once" Condition="'$(SkipSync)' == 'true' AND !Exists('$(MSBuildProjectDirectory)/../TempTypeSpecFiles')" />
455+
<Exec Command="npm install --prefix $(MSBuildProjectDirectory)/../ @azure-tools/typespec-client-generator-cli --no-save" />
456+
<Exec Condition="'$(SkipSync)' == 'true'" Command="$(_TypeSpecProjectGenerateCommand) $(_SaveInputs) $(_TypespecAdditionalOptions) $(_Debug)"/>
457+
<Exec Condition="'$(SkipSync)' != 'true'" Command="$(_TypeSpecProjectSyncAndGenerateCommand) $(_SaveInputs) $(_LocalSpecRepo) $(_TypespecAdditionalOptions) $(_Debug)"/>
458+
</Target>
438459

439460
<Import Project="$(CentralPackageVersionPackagePath)\Sdk.targets" />
440461
</Project>

sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/src/Azure.Messaging.EventGrid.Namespaces.csproj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
<ApiCompatVersion>1.1.0</ApiCompatVersion>
88
<PackageTags>Azure;Event Grid;CloudEvent;$(PackageCommonTags)</PackageTags>
99
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
10-
<IncludeOperationsSharedSource>true</IncludeOperationsSharedSource>
11-
<DisableEnhancedAnalysis>true</DisableEnhancedAnalysis>
10+
<IncludeAutorestDependency>false</IncludeAutorestDependency>
1211
</PropertyGroup>
1312

14-
<ItemGroup>
13+
<ItemGroup>
14+
<Compile Include="$(AzureCoreSharedSources)AppContextSwitchHelper.cs" LinkBase="Shared/Core" />
1515
<Compile Include="$(AzureCoreSharedSources)AzureKeyCredentialPolicy.cs" LinkBase="Shared/Core" />
1616
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="Shared/Core" />
17+
<Compile Include="$(AzureCoreSharedSources)ClientDiagnostics.cs" LinkBase="Shared/Core" />
18+
<Compile Include="$(AzureCoreSharedSources)DiagnosticScopeFactory.cs" LinkBase="Shared/Core" />
19+
<Compile Include="$(AzureCoreSharedSources)DiagnosticScope.cs" LinkBase="Shared/Core" />
20+
<Compile Include="$(AzureCoreSharedSources)HttpMessageSanitizer.cs" LinkBase="Shared/Core" />
21+
<Compile Include="$(AzureCoreSharedSources)RawRequestUriBuilder.cs" LinkBase="Shared/Core" />
22+
<Compile Include="$(AzureCoreSharedSources)TrimmingAttribute.cs" LinkBase="Shared/Core" />
23+
<Compile Include="$(AzureCoreSharedSources)TypeFormatters.cs" LinkBase="Shared/Core" />
1724
</ItemGroup>
1825

1926
<ItemGroup>

sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/src/properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
99

1010
[assembly: AzureResourceProviderNamespace("Microsoft.EventGrid")]
11-
[assembly: CodeGenSuppressType("MessagingEventGridNamespacesClientBuilderExtensions")]

0 commit comments

Comments
 (0)