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

Add task for metadata resolution #9313

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
89 changes: 89 additions & 0 deletions src/Tasks.UnitTests/GetAssembliesMetadata_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETFRAMEWORK
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.UnitTests;
using Shouldly;
using Xunit;
using Xunit.Sdk;
using Microsoft.Build.UnitTests.Shared;
using Xunit.Abstractions;

namespace Microsoft.Build.Tasks.UnitTests
{
public class GetAssembliesMetadata_Tests
{
private static string TestAssembliesPaths { get; } = Path.Combine(AppContext.BaseDirectory, "TestResources", "Projects");

private readonly ITestOutputHelper _testOutput;

public GetAssembliesMetadata_Tests(ITestOutputHelper testOutput)
{
_testOutput = testOutput;
}

[Fact]
public void CheckPresenceOfCustomCOMAssemblyAttributes()
{
string testSolutionPath = Path.Combine(TestAssembliesPaths, "Custom_COM");
RunnerUtilities.ExecMSBuild(testSolutionPath, out bool success, _testOutput);
string assemblyPath = Path.Combine(testSolutionPath, "Custom_COM", "bin", "Debug", "Custom_COM.dll");
GetAssembliesMetadata t = new() { AssemblyPaths = new[] { assemblyPath } };

bool isSuccess = t.Execute();

success.ShouldBeTrue();
isSuccess.ShouldBeTrue();
t.AssembliesMetadata[0].ItemSpec.ShouldBe(assemblyPath);
t.AssembliesMetadata[0].GetMetadata("AssemblyName").ShouldBe("Custom_COM");
t.AssembliesMetadata[0].GetMetadata("IsImportedFromTypeLib").ShouldBe("False");
t.AssembliesMetadata[0].GetMetadata("RevisionNumber").ShouldBe("4");
t.AssembliesMetadata[0].GetMetadata("IsAssembly").ShouldBe("True");
t.AssembliesMetadata[0].GetMetadata("RuntimeVersion").ShouldBe("v4.0.30319");
t.AssembliesMetadata[0].GetMetadata("MajorVersion").ShouldBe("1");
t.AssembliesMetadata[0].GetMetadata("MinorVersion").ShouldBe("2");
t.AssembliesMetadata[0].GetMetadata("PeKind").ShouldBe("1");
t.AssembliesMetadata[0].GetMetadata("BuildNumber").ShouldBe("3");
t.AssembliesMetadata[0].GetMetadata("Description").ShouldBe("description for com");
t.AssembliesMetadata[0].GetMetadata("Culture").ShouldBeEmpty();
t.AssembliesMetadata[0].GetMetadata("TargetFrameworkMoniker").ShouldBe(".NETFramework,Version=v4.7.2");
t.AssembliesMetadata[0].GetMetadata("DefaultAlias").ShouldBe("Custom_COM");
t.AssembliesMetadata[0].GetMetadata("PublicHexKey").ShouldBeEmpty();
}

[Fact]
public void CheckPresenceOfCOMAssemblyAttributes()
{
string pathToWinFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
string assemblyPath = Path.Combine(pathToWinFolder, "Microsoft.NET", "Framework", "v4.0.30319", "mscorlib.dll");
GetAssembliesMetadata t = new() { AssemblyPaths = new[] { assemblyPath } };

bool isSuccess = t.Execute();

isSuccess.ShouldBeTrue();
t.AssembliesMetadata[0].ItemSpec.ShouldBe(assemblyPath);
t.AssembliesMetadata[0].GetMetadata("AssemblyName").ShouldBe("mscorlib");
t.AssembliesMetadata[0].GetMetadata("IsImportedFromTypeLib").ShouldBe("False");
t.AssembliesMetadata[0].GetMetadata("RevisionNumber").ShouldBe("0");
t.AssembliesMetadata[0].GetMetadata("IsAssembly").ShouldBe("True");
t.AssembliesMetadata[0].GetMetadata("RuntimeVersion").ShouldBe("v4.0.30319");
t.AssembliesMetadata[0].GetMetadata("MajorVersion").ShouldBe("4");
t.AssembliesMetadata[0].GetMetadata("MinorVersion").ShouldBe("0");
t.AssembliesMetadata[0].GetMetadata("PeKind").ShouldBe("3");
t.AssembliesMetadata[0].GetMetadata("BuildNumber").ShouldBe("0");
t.AssembliesMetadata[0].GetMetadata("Description").ShouldBe("mscorlib.dll");
t.AssembliesMetadata[0].GetMetadata("Culture").ShouldBeEmpty();
t.AssembliesMetadata[0].GetMetadata("TargetFrameworkMoniker").ShouldBeEmpty();
t.AssembliesMetadata[0].GetMetadata("DefaultAlias").ShouldBe("mscorlib");
t.AssembliesMetadata[0].GetMetadata("PublicHexKey").ShouldBe("00000000000000000400000000000000");
}
}
}
#endif
16 changes: 16 additions & 0 deletions src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>$(RuntimeOutputTargetFrameworks)</TargetFrameworks>
<PlatformTarget>$(RuntimeOutputPlatformTarget)</PlatformTarget>
<IsPackable>false</IsPackable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

<AssemblyName>Microsoft.Build.Tasks.UnitTests</AssemblyName>
<IsTestProject>true</IsTestProject>
Expand Down Expand Up @@ -76,6 +77,18 @@
<None Include="..\Shared\UnitTests\xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestResources\Projects\Custom_COM\Custom_COM\Class1.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestResources\Projects\Custom_COM\Custom_COM.sln">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestResources\Projects\Custom_COM\Custom_COM\Custom_COM.csproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestResources\Projects\Custom_COM\Custom_COM\Properties\AssemblyInfo.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -148,6 +161,9 @@

<ItemGroup>
<None Update="ResourceHandling\*.txt" CopyToOutputDirectory="PreserveNewest" />
<None Update="TestResources\Projects\Custom_COM\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestResources\lorem.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34119.44
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Custom_COM", "Custom_COM\Custom_COM.csproj", "{A48EFB66-2596-4C6A-87AB-C8A765E54429}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A48EFB66-2596-4C6A-87AB-C8A765E54429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A48EFB66-2596-4C6A-87AB-C8A765E54429}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A48EFB66-2596-4C6A-87AB-C8A765E54429}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A48EFB66-2596-4C6A-87AB-C8A765E54429}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3A8E37B3-7F2C-491C-9742-92319262C651}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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

namespace Custom_COM
{
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ITest
{
}

[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Tester.Numbers")]
public class Test : ITest
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A48EFB66-2596-4C6A-87AB-C8A765E54429}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Custom_COM</RootNamespace>
<AssemblyName>Custom_COM</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Custom_COM")]
[assembly: AssemblyDescription("description for com")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MSFT")]
[assembly: AssemblyProduct("Custom_COM")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("Mark")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a48efb66-2596-4c6a-87ab-c8a765e54429")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.3.4")]
[assembly: AssemblyFileVersion("1.2.3.4")]
[assembly: NeutralResourcesLanguage("cs")]
48 changes: 48 additions & 0 deletions src/Tasks/AssemblyDependency/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Build.Tasks.AssemblyDependency
{
/// <summary>
/// Collection of assembly attributes.
/// </summary>
internal sealed class AssemblyAttributes
{
public string AssemblyFullPath { get; set; } = string.Empty;

public string AssemblyName { get; set; } = string.Empty;

public string DefaultAlias { get; set; } = string.Empty;

public string Description { get; set; } = string.Empty;

public string Culture { get; set; } = string.Empty;

public string RuntimeVersion { get; set; } = string.Empty;

public ushort MajorVersion { get; set; }

public ushort MinorVersion { get; set; }

public ushort BuildNumber { get; set; }

public ushort RevisionNumber { get; set; }

// it is a byte[] converted to string
public string PublicHexKey { get; set; } = string.Empty;

public bool IsAssembly { get; set; }

public uint PeKind { get; set; }

public bool IsImportedFromTypeLib { get; set; }

public string TargetFrameworkMoniker { get; set; } = string.Empty;
}
}
Loading
Loading