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

use alternative way to generate assemblyinfo.cs #1387

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions powershell/generators/AssemblyInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Project } from '../internal/project';

export async function generateAssemblyInfo(project: Project) {
if (!project.azure || !project.assemblyInfoPath) {
return;
}

const info = `${project.csharpCommentHeaderForCsharp}

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: System.Reflection.AssemblyCompanyAttribute("${project.assemblyCompany}")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("${project.assemblyCopyright}")]
[assembly: System.Reflection.AssemblyProductAttribute("${project.assemblyProduct}")]
[assembly: System.Reflection.AssemblyTitleAttribute("${project.assemblyProduct} - ${project.title}")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.1.0.0")]
[assembly: System.Reflection.AssemblyVersionAttribute("0.1.0.0")]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
[assembly: System.CLSCompliantAttribute(false)]`;

project.state.writeFile(project.assemblyInfoPath, info, undefined, 'source-file-csharp');
}
18 changes: 1 addition & 17 deletions powershell/generators/csproj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ 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 @@ -39,6 +23,7 @@ export async function generateCsproj(project: Project) {
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<AssemblyName>${project.dllName}</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>${project.projectNamespace}</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Expand All @@ -52,7 +37,6 @@ 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
3 changes: 2 additions & 1 deletion powershell/plugins/powershell-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import { generateGitAttributes } from '../generators/gitattributes';
import { generateReadme } from '../generators/readme';
import { generateScriptCmdlets } from '../generators/script-cmdlet';
import { TspHost } from '../utils/tsp-host';
import { State } from '../internal/state';
import { ModelState } from '../utils/model-state';
import { PwshModel } from '../utils/PwshModel';
import { generateAssemblyInfo } from '../generators/AssemblyInfo';

const sourceFileCSharp = 'source-file-csharp';
const resources = `${__dirname}/../../resources`;
Expand Down Expand Up @@ -138,6 +138,7 @@ export async function powershellV2(service: Host | TspHost, state?: ModelState<P
await generateGitIgnore(project);
await generateGitAttributes(project);
await generateReadme(project);
await generateAssemblyInfo(project);

await generateScriptCmdlets(project);
} catch (E) {
Expand Down
7 changes: 0 additions & 7 deletions powershell/resources/assets/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ 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