Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 7d6c8b9

Browse files
authored
Add support for generating the C# SDK assembly using CSC.exe on Windows PS. (#312)
Latest version of AutoRest generates C# 6 code. Add-Type on Windows PS doesn't support compilation of C# 6 code. Made required changes to leverage the CSC.exe for generating the C# SDK assembly on Windows PowerShell. Additional changes - Updated readme and run-tests.ps1 - Removed stale source code files under PSSwagger.Azure.Helpers folder. - Removed `Import-Module '$PSScriptRoot\PSSwaggerUtility'` usage for PowerShellCore.
1 parent 40c9abe commit 7d6c8b9

9 files changed

+237
-303
lines changed

PSSwagger/PSSwagger.Azure.Helpers/PSSwagger.Azure.Helpers.psd1

-39
This file was deleted.

PSSwagger/PSSwagger.Azure.Helpers/PSSwagger.Azure.Helpers.psm1

-141
This file was deleted.

PSSwagger/PSSwagger.Azure.Helpers/Test-CoreRequirements.ps1

-1
This file was deleted.

PSSwagger/PSSwagger.Azure.Helpers/Test-FullRequirements.ps1

-1
This file was deleted.

PSSwagger/PSSwagger.Resources.psd1

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ConvertFrom-StringData @'
2525
SamePropertyName=Same property name '{0}' is defined in a definition '{1}' with AllOf inheritance.
2626
DataTypeNotImplemented=Please get an implementation of '{0}' for '{1}'
2727
AutoRestNotInPath=Unable to find AutoRest in PATH environment. Ensure the PATH is updated.
28+
CscExeNotInPath=Unable to find CSC.exe in PATH environment. Ensure the PATH is updated with CSC.exe location.
2829
AutoRestError=AutoRest resulted in an error
2930
SwaggerParamsMissing=No parameters in the Swagger
3031
SwaggerDefinitionsMissing=No definitions in the Swagger

PSSwagger/PSSwagger.psm1

+8-4
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,12 @@ function ConvertTo-CsharpCode
587587

588588
$autoRestExePath = "AutoRest"
589589
if (-not (get-command -name $autoRestExePath)) {
590-
throw $LocalizedData.AutoRestNotInPath
590+
throw $LocalizedData.AutoRestNotInPath
591+
}
592+
593+
if (-not (Get-OperatingSystemInfo).IsCore -and
594+
(-not (Get-Command -Name 'Csc.Exe' -ErrorAction Ignore))) {
595+
throw $LocalizedData.CscExeNotInPath
591596
}
592597

593598
$outputDirectory = $SwaggerMetaDict['outputDirectory']
@@ -718,7 +723,7 @@ function ConvertTo-CsharpCode
718723
-CliXmlTmpPath $cliXmlTmpPath"
719724

720725
$success = & "powershell" -command "& {$command}"
721-
726+
722727
$codeReflectionResult = Import-CliXml -Path $cliXmlTmpPath
723728
if ($codeReflectionResult.ContainsKey('VerboseMessages') -and $codeReflectionResult.VerboseMessages -and ($codeReflectionResult.VerboseMessages.Count -gt 0)) {
724729
$verboseMessages = $codeReflectionResult.VerboseMessages -Join [Environment]::NewLine
@@ -773,8 +778,7 @@ function ConvertTo-CsharpCode
773778
}
774779
$dependencies = Get-PSSwaggerExternalDependencies -Azure:$codeCreatedByAzureGenerator -Framework 'netstandard1'
775780
$microsoftRestClientRuntimeAzureRequiredVersion = if ($dependencies.ContainsKey('Microsoft.Rest.ClientRuntime.Azure')) { $dependencies['Microsoft.Rest.ClientRuntime.Azure'].RequiredVersion } else { '' }
776-
$command = "Import-Module '$PSScriptRoot\PSSwaggerUtility';
777-
Add-PSSwaggerClientType -OutputAssemblyName '$outAssembly' ``
781+
$command = "PSSwaggerUtility\Add-PSSwaggerClientType -OutputAssemblyName '$outAssembly' ``
778782
-ClrPath '$clrPath' ``
779783
-CSharpFiles $allCSharpFilesArrayString ``
780784
-MicrosoftRestClientRuntimeAzureRequiredVersion '$microsoftRestClientRuntimeAzureRequiredVersion' ``

0 commit comments

Comments
 (0)