Skip to content
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
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.5.0" />
<PackageVersion Include="Microsoft.Build" Version="17.5.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
Expand All @@ -18,7 +19,6 @@
<PackageVersion Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="6.0.0-preview.5.21301.5" />
<PackageVersion Include="Mono.Cecil" Version="0.11.5" />
<PackageVersion Include="Buildalyzer" Version="5.0.0" />
<PackageVersion Include="coverlet.msbuild" Version="3.2.0" />
<PackageVersion Include="MSBuild.ProjectCreation" Version="10.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Mono.Cecil" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
Expand Down
20 changes: 10 additions & 10 deletions src/GitVersion.App.Tests/VersionWriterTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using GitVersion.Core.Tests.Helpers;
using GitVersion.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Extensions.DependencyInjection;
using Mono.Cecil;

namespace GitVersion.App.Tests;

Expand Down Expand Up @@ -46,17 +47,16 @@ public void WriteVersionShouldWriteFileVersionWithPrereleaseTag()

private static Assembly GenerateAssembly(Version fileVersion, string prereleaseInfo)
{
var definition = new AssemblyNameDefinition("test-asm", fileVersion);

var asmDef = AssemblyDefinition.CreateAssembly(definition, "test-asm", ModuleKind.Dll);
var constructor = typeof(AssemblyInformationalVersionAttribute).GetConstructor(new[] { typeof(string) });
var methodReference = asmDef.MainModule.ImportReference(constructor);
var customAttribute = new CustomAttribute(methodReference);
customAttribute.ConstructorArguments.Add(new CustomAttributeArgument(asmDef.MainModule.TypeSystem.String, fileVersion + prereleaseInfo));
asmDef.CustomAttributes.Add(customAttribute);
var attribute = typeof(AssemblyInformationalVersionAttribute);
var csharpCode = $@"[assembly: {attribute.FullName}(""{fileVersion + prereleaseInfo}"")]";
var compilation = CSharpCompilation.Create("test-asm")
.WithOptions(new(OutputKind.DynamicallyLinkedLibrary))
.AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
.AddReferences(MetadataReference.CreateFromFile(attribute.Assembly.Location))
.AddSyntaxTrees(CSharpSyntaxTree.ParseText(csharpCode));

using var memoryStream = new MemoryStream();
asmDef.Write(memoryStream);
compilation.Emit(memoryStream);

return Assembly.Load(memoryStream.ToArray());
}
Expand Down