Install netfx dlls to GAC for tests (#2164)

* Install netfx dlls to GAC before integration test

* fix run order

* Update tools/GacInstallTool/Program.cs

Co-authored-by: Paulo Janotti <pjanotti@splunk.com>

* remove before

* add packages.props reference

* add comment

* Add possibility to uninstall

* pr feedback

---------

Co-authored-by: Paulo Janotti <pjanotti@splunk.com>
This commit is contained in:
Rasmus Kuusmann 2023-02-07 22:47:54 +02:00 committed by GitHub
parent 70d92b847a
commit 6e3a1ec197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 136 additions and 3 deletions

View File

@ -131,6 +131,10 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.MassTransit", "test\test-applications\integrations\TestApplication.MassTransit\TestApplication.MassTransit.csproj", "{06664166-35D6-484D-9171-DCB99D1D310A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{00F4C92D-6652-4BD8-A334-B35D3E711BE6}"
ProjectSection(SolutionItems) = preProject
tools\Directory.Build.targets = tools\Directory.Build.targets
tools\Directory.Packages.props = tools\Directory.Packages.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationsJsonGenerator", "tools\IntegrationsJsonGenerator\IntegrationsJsonGenerator.csproj", "{0A950D85-E813-4CA3-8927-334BB7787372}"
EndProject
@ -154,16 +158,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.AspNet.NetF
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.MultipleAppDomains.NetFramework", "test\test-applications\integrations\TestApplication.MultipleAppDomains.NetFramework\TestApplication.MultipleAppDomains.NetFramework.csproj", "{A0338846-2AF8-4D96-ADA7-EBD4F010D08F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.CustomSdk", "test\test-applications\integrations\TestApplication.CustomSdk\TestApplication.CustomSdk.csproj", "{7B363F47-1DB8-44CF-8388-A41F9366C9DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.CustomSdk", "test\test-applications\integrations\TestApplication.CustomSdk\TestApplication.CustomSdk.csproj", "{7B363F47-1DB8-44CF-8388-A41F9366C9DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.Quartz", "test\test-applications\integrations\TestApplication.Quartz\TestApplication.Quartz.csproj", "{B48780CE-8AAB-44D3-9CD1-8491584352B5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "test\Benchmarks\Benchmarks.csproj", "{B1E71654-E784-4A39-BE45-8671E027B6D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.EntityFrameworkCore", "test\test-applications\integrations\TestApplication.EntityFrameworkCore\TestApplication.EntityFrameworkCore.csproj", "{036A56A4-4EEF-42E3-9857-B9B00D302BF9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.EntityFrameworkCore", "test\test-applications\integrations\TestApplication.EntityFrameworkCore\TestApplication.EntityFrameworkCore.csproj", "{036A56A4-4EEF-42E3-9857-B9B00D302BF9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DependencyListGenerator", "tools\DependencyListGenerator\DependencyListGenerator.csproj", "{D6181786-C7F1-400D-A678-8DC300485429}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GacInstallTool", "tools\GacInstallTool\GacInstallTool.csproj", "{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -780,6 +786,18 @@ Global
{D6181786-C7F1-400D-A678-8DC300485429}.Release|x64.Build.0 = Release|Any CPU
{D6181786-C7F1-400D-A678-8DC300485429}.Release|x86.ActiveCfg = Release|Any CPU
{D6181786-C7F1-400D-A678-8DC300485429}.Release|x86.Build.0 = Release|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Debug|x64.ActiveCfg = Debug|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Debug|x64.Build.0 = Debug|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Debug|x86.ActiveCfg = Debug|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Debug|x86.Build.0 = Debug|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Release|Any CPU.Build.0 = Release|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Release|x64.ActiveCfg = Release|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Release|x64.Build.0 = Release|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Release|x86.ActiveCfg = Release|Any CPU
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -840,6 +858,7 @@ Global
{B1E71654-E784-4A39-BE45-8671E027B6D7} = {5C915382-C886-457D-8641-9E766D8E5A17}
{036A56A4-4EEF-42E3-9857-B9B00D302BF9} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{D6181786-C7F1-400D-A678-8DC300485429} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}

View File

@ -4,11 +4,13 @@ using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.MSBuild;
using Serilog;
using static Nuke.Common.EnvironmentInfo;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.Docker.DockerTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
partial class Build
@ -177,4 +179,30 @@ partial class Build
AssemblyRedirectionSourceGenerator.Generate(netFxAssembliesFolder, generatedSourceFile);
});
Target InstallNetFxAssembliesGAC => _ => _
.Unlisted()
.After(BuildTracer)
.OnlyWhenStatic(() => IsWin)
.Executes(() => RunNetFxGacOperation("-i"));
/// <remarks>
/// Warning: This target could cause potential harm to your system by removing a required library from GAC.
/// </remarks>
Target UninstallNetFxAssembliesGAC => _ => _
.Description("Removes .NET Framework output libraries from the GAC.")
.After(BuildTracer)
.OnlyWhenStatic(() => IsWin)
.Executes(() => RunNetFxGacOperation("-u"));
private void RunNetFxGacOperation(string operation)
{
var netFxAssembliesFolder = TracerHomeDirectory / MapToFolderOutput(TargetFramework.NET462);
var installTool = Solution.GetProject(Projects.Tools.GacInstallTool);
DotNetRun(s => s
.SetProjectFile(installTool)
.SetConfiguration(BuildConfiguration)
.SetApplicationArguments($"{operation} {netFxAssembliesFolder}"));
}
}

View File

@ -380,6 +380,7 @@ partial class Build
Target RunManagedIntegrationTests => _ => _
.Unlisted()
.After(InstallNetFxAssembliesGAC)
.After(RunManagedUnitTests)
.Executes(() =>
{

View File

@ -111,6 +111,7 @@ partial class Build : NukeBuild
.DependsOn(CompileMocks)
.DependsOn(PublishMocks)
.DependsOn(PublishIisTestApplications)
.DependsOn(InstallNetFxAssembliesGAC)
.DependsOn(RunManagedTests);
string ContainersFilter()

View File

@ -34,6 +34,6 @@ public static class Projects
public static class Tools
{
public const string IntegrationsJsonGenerator = "IntegrationsJsonGenerator";
public const string GacInstallTool = "GacInstallTool";
}
}

View File

@ -0,0 +1,3 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)..\Common.targets" />
</Project>

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.EnterpriseServices" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,67 @@
// <copyright file="Program.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace GacInstallTool;
internal class Program
{
private const string InstallFlag = "-i";
private const string UninstallFlag = "-u";
public static void Main(string[] args)
{
if (args.Length < 2)
{
throw new InvalidOperationException("Missing arguments. Provide -i path/to/dir to install and -u path/to/dir to uninstall.");
}
var flag = args[0];
var dir = args[1];
if (flag != InstallFlag && flag != UninstallFlag)
{
throw new InvalidOperationException($"Unknown flag: {flag}.");
}
if (!Directory.Exists(dir))
{
throw new DirectoryNotFoundException($"Directory does not exist: {dir}");
}
var install = flag == InstallFlag;
var publisher = new System.EnterpriseServices.Internal.Publish();
var files = Directory.GetFiles(dir, "*.dll");
foreach (var file in files)
{
// Publisher API call can silently fail.
if (install)
{
publisher.GacInstall(file);
}
else
{
publisher.GacRemove(file);
}
}
var resultText = install
? $"Success: Installed {files.Length} libraries in the GAC."
: $"Success: Uninstalled {files.Length} libraries from the GAC.";
Console.WriteLine(resultText);
}
}