Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate assemblyinfo.cs for new module #1376

Merged
merged 8 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 additions & 0 deletions powershell/internal/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,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 +152,10 @@ export class Project extends codeDomProject {
public readme!: string;
public afterBuildTasksPath!: string;
public afterBuildTasksArgs!: string;
public assemblyInfoFolder!: string;
public assemblyCompany!: string;
public assemblyProduct!: string;
public assemblyCopyright!: string;
public dllName!: string;
public dll!: string;
public psd1!: string;
Expand Down Expand Up @@ -284,6 +289,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 +346,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.assemblyInfoFolder = await this.state.getValue('assemblyInfo-folder', '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just hardcode the assemblyInfoFolder to Properties

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
3 changes: 3 additions & 0 deletions powershell/plugins/powershell-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export async function powershellV2(service: Host | TspHost, state?: ModelState<P
await project.state.protectFiles(project.examplesFolder);
await project.state.protectFiles(project.resourcesFolder);
await project.state.protectFiles(project.uxFolder);
if (project.azure) {
await project.state.protectFiles(project.assemblyInfoFolder);
}

// wait for all the generation to be done
await copyRequiredFiles(project);
Expand Down
8 changes: 7 additions & 1 deletion powershell/resources/assets/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,17 @@ if (Test-Path (Join-Path $PSScriptRoot 'generate-portal-ux.ps1'))
. (Join-Path $PSScriptRoot 'generate-portal-ux.ps1')
}

$assemblyInfoPath = Join-Path $PSScriptRoot 'Properties' 'AssemblyInfo.cs'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only have it for Azure.

if (-not (Test-Path $assemblyInfoPath)) {
Write-Host -ForegroundColor Green 'Creating assembly info...'
New-AssemblyInfo
}

if (-not $DisableAfterBuildTasks){
$afterBuildTasksPath = Join-Path $PSScriptRoot '${$project.afterBuildTasksPath}'
$afterBuildTasksArgs = ConvertFrom-Json '${$project.afterBuildTasksArgs}' -AsHashtable
if(Test-Path -Path $afterBuildTasksPath -PathType leaf){
Write-Host -ForegroundColor Green 'Running after build tasks...'
Write-Host -ForegroundColor Green 'Executing after build tasks...'
. $afterBuildTasksPath @afterBuildTasksArgs
}
}
Expand Down
1 change: 1 addition & 0 deletions powershell/resources/built-time-cmdlets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<Compile Include="psruntime\BuildTime\Cmdlets\ExportExampleStub.cs" />
<Compile Include="psruntime\BuildTime\Cmdlets\GetModuleGuid.cs" />
<Compile Include="psruntime\BuildTime\Cmdlets\ExportPsd1.cs" />
<Compile Include="psruntime\BuildTime\Cmdlets\NewAssemblyInfo.cs" />
<Compile Include="psruntime\BuildTime\Cmdlets\GetCommonParameter.cs" />
<Compile Include="psruntime\BuildTime\Models\PsHelpMarkdownOutputs.cs" />
<Compile Include="psruntime\BuildTime\Models\PsMarkdownTypes.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ protected override void ProcessRecord()
else
{
var aliasesList = functionInfos.SelectMany(fi => fi.ScriptBlock.Attributes).ToAliasNames().ToPsList();
if (!String.IsNullOrEmpty(aliasesList)) {
if (!String.IsNullOrEmpty(aliasesList))
{
sb.AppendLine($@"{Indent}AliasesToExport = {aliasesList}");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Text;

namespace Microsoft.Rest.ClientRuntime.PowerShell
{
[Cmdlet("New", "AssemblyInfo")]
[DoNotExport]
public class NewAssemblyInfo : PSCmdlet
{
private readonly string assemblyInfoPath = Path.Combine("${$project.baseFolder}", "Properties", "AssemblyInfo.cs");
private const string assemblyName = "${$project.title}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use $(module-name) instead of title here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module-name is Az.xxx, title is without Az, I want it to be without 'Az'

private const string assemblyVersion = "${$project.moduleVersion}";
private const string assemblyCompanyName = "${$project.assemblyCompany}";
private const string assemblyProduct = "${$project.assemblyProduct}";
private const string assemblyCopyright = "${$project.assemblyCopyright}";
protected override void ProcessRecord()
{
try
{
if (File.Exists(assemblyInfoPath))
{
return;
}
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"
# ----------------------------------------------------------------------------------
${$project.pwshCommentHeaderForCsharp}
# ----------------------------------------------------------------------------------
");
sb.Append($"{Environment.NewLine}");
sb.AppendLine("using System;");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider hardcode all the stuff except for assemblyName, Guid, and assemblyVersion.

sb.AppendLine("using System.Reflection;");
sb.AppendLine("using System.Runtime.InteropServices;");
sb.Append($"{Environment.NewLine}");
sb.AppendLine($"[assembly: AssemblyTitle(\"Microsoft Azure Powershell - {assemblyName}\")]");
sb.AppendLine($"[assembly: AssemblyCompany(\"{assemblyCompanyName}\")]");
sb.AppendLine($"[assembly: AssemblyProduct(\"{assemblyProduct}\")]");
sb.AppendLine($"[assembly: AssemblyCopyright(\"{assemblyCopyright}\")]");
sb.Append($"{Environment.NewLine}");
sb.AppendLine("[assembly: ComVisible(false)]");
sb.AppendLine("[assembly: CLSCompliant(false)]");
sb.AppendLine($"[assembly: Guid(\"{Guid.NewGuid()}\")]");
sb.AppendLine($"[assembly: AssemblyVersion(\"{assemblyVersion}\")]");
sb.Append($"[assembly: AssemblyFileVersion(\"{assemblyVersion}\")]");

FileInfo assemblyInfo = new FileInfo(assemblyInfoPath);
assemblyInfo.Directory.Create();
File.WriteAllText(assemblyInfo.FullName, sb.ToString());
}
catch (Exception ee)
{
Console.WriteLine($"${ee.GetType().Name}/{ee.StackTrace}");
throw ee;
}
}
}
}