Skip to content

Commit

Permalink
generate assemblyinfo.cs for azure (#1384)
Browse files Browse the repository at this point in the history
* add assemblyinfo to csproj

* insert header for assemblyinfo

* move insert header after compilation

* do not insert header if assemblyinfopaht not present

* fix

* remove write-host for insert license
  • Loading branch information
VeryEarly authored Sep 30, 2024
1 parent 5d5411f commit 81740c0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
18 changes: 17 additions & 1 deletion powershell/generators/csproj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ export async function generateCsproj(project: Project) {
<DefineConstants>TRACE;RELEASE;NETSTANDARD;SIGN</DefineConstants>` :
' <DefineConstants>TRACE;RELEASE;NETSTANDARD</DefineConstants>';

const assemblyinfo = project.azure ? ` <PropertyGroup>
<GeneratedAssemblyInfoFile>${project.assemblyInfoPath}</GeneratedAssemblyInfoFile>
<Company>${project.assemblyCompany}</Company>
<Product>${project.assemblyProduct}</Product>
<CopyRight>${project.assemblyCopyright}</CopyRight>
<AssemblyTitle>${project.assemblyProduct} - ${project.title}</AssemblyTitle>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.InteropServices.ComVisibleAttribute">
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.CLSCompliantAttribute">
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>
</ItemGroup>` : '';

project.state.writeFile(project.csproj, `<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
Expand All @@ -36,7 +52,7 @@ export async function generateCsproj(project: Project) {
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
${assemblyinfo}
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DelaySign>false</DelaySign>
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
Expand Down
2 changes: 2 additions & 0 deletions powershell/generators/gitignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ tools
custom/*.psm1
custom/autogen-model-cmdlets
test/*-TestResults.xml
license.txt
/*.ps1
/*.psd1
/*.ps1xml
/*.psm1
/*.snk
Expand Down
15 changes: 14 additions & 1 deletion powershell/internal/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class Project extends codeDomProject {
public pwshCommentHeader!: string;
public pwshCommentHeaderForCsharp!: string;
public csharpCommentHeader!: string;
public csharpCommentHeaderForCsharp!: string;
public cmdletFolder!: string;
public modelCmdletFolder!: string;
public endpointResourceIdKeyName!: string;
Expand All @@ -142,6 +143,7 @@ export class Project extends codeDomProject {
public uxFolder!: string;
public serviceName!: string;
public moduleName!: string;
public title!: string;
public rootModuleName!: string;
public csproj!: string;
public nuspec!: string;
Expand All @@ -151,6 +153,10 @@ export class Project extends codeDomProject {
public readme!: string;
public afterBuildTasksPath!: string;
public afterBuildTasksArgs!: string;
public assemblyInfoPath!: string;
public assemblyCompany!: string;
public assemblyProduct!: string;
public assemblyCopyright!: string;
public dllName!: string;
public dll!: string;
public psd1!: string;
Expand Down Expand Up @@ -262,6 +268,7 @@ export class Project extends codeDomProject {
: this.license,
'//'
);
this.csharpCommentHeaderForCsharp = this.csharpCommentHeader.replace(/"/g, '""');

// modelcmdlets are models that we will create cmdlets for.
this.modelCmdlets = [];
Expand All @@ -284,6 +291,7 @@ export class Project extends codeDomProject {
this.serviceName = this.model.language.default.serviceName;
this.subjectPrefix = this.model.language.default.subjectPrefix;
this.moduleName = await this.state.getValue('module-name');
this.title = await this.state.getValue('title');
this.rootModuleName = await this.state.getValue('root-module-name', '');
this.dllName = await this.state.getValue('dll-name');
// Azure PowerShell data plane configuration
Expand Down Expand Up @@ -340,6 +348,11 @@ export class Project extends codeDomProject {
const afterBuildTasksArgsDictionary: Dictionary<string> = await this.state.getValue<Dictionary<string>>('after-build-tasks-args', {});
this.afterBuildTasksArgs = JSON.stringify(afterBuildTasksArgsDictionary);

this.assemblyInfoPath = await this.state.getValue('assemblyInfo-path', '');
this.assemblyCompany = await this.state.getValue('assembly-company', '');
this.assemblyProduct = await this.state.getValue('assembly-product', '');
this.assemblyCopyright = await this.state.getValue('assembly-copyright', '');

// excluded properties in table view
const excludedList = <Array<string>>(
values(
Expand Down Expand Up @@ -423,4 +436,4 @@ export class Project extends codeDomProject {
private convertToPsListAsString(items: Array<string>): string {
return items ? items.map((i) => `'${i}'`).join(', ') : 'undefined';
}
}
}
14 changes: 11 additions & 3 deletions powershell/resources/assets/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ if(-not $NotIsolated -and -not $Debugger) {
$binFolder = Join-Path $PSScriptRoot '${$lib.path.relative($project.baseFolder, $project.binFolder)}'
$objFolder = Join-Path $PSScriptRoot '${$lib.path.relative($project.baseFolder, $project.objFolder)}'

$isAzure = [System.Convert]::ToBoolean('${$project.azure}')

if(-not $Debugger) {
Write-Host -ForegroundColor Green 'Cleaning build folders...'
$null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path $binFolder, $objFolder
Expand All @@ -86,6 +88,13 @@ if(-not $Debugger) {
$null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path (Join-Path $binFolder 'Debug'), (Join-Path $binFolder 'Release')
}

if ($isAzure -And '${$project.assemblyInfoPath}') {
$assemblyInfoPath = Join-Path $PSScriptRoot '${$project.assemblyInfoPath}'
$header = '${$project.csharpCommentHeaderForCsharp}'
$content = $header + [Environment]::NewLine + [Environment]::NewLine + (Get-Content $assemblyInfoPath -Raw)
$content | Set-Content $assemblyInfoPath -Force
}

$dll = Join-Path $PSScriptRoot '${$lib.path.relative($project.baseFolder, $project.dll)}'
if(-not (Test-Path $dll)) {
Write-Error "Unable to find output assembly in '$binFolder'."
Expand Down Expand Up @@ -140,7 +149,7 @@ if($NoDocs) {
$null = Get-ChildItem -Path $docsFolder -Recurse -Exclude 'README.md' | Remove-Item -Recurse -ErrorAction SilentlyContinue
}
$null = New-Item -ItemType Directory -Force -Path $docsFolder
$addComplexInterfaceInfo = ![System.Convert]::ToBoolean('${$project.azure}')
$addComplexInterfaceInfo = !$isAzure
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ModuleDescription $moduleDescription -DocsFolder $docsFolder -ExamplesFolder $examplesFolder -ModuleGuid $guid -AddComplexInterfaceInfo:$addComplexInterfaceInfo
}

Expand Down Expand Up @@ -175,5 +184,4 @@ if (-not $DisableAfterBuildTasks){
}
}


Write-Host -ForegroundColor Green '-------------Done-------------'
Write-Host -ForegroundColor Green '-------------Done-------------'

0 comments on commit 81740c0

Please sign in to comment.