From e2584b8925ad9301f28bafa4a7286261f5d12714 Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Tue, 7 Dec 2021 14:47:29 -0800 Subject: [PATCH] Fix appdomains under visual studio --- eng/Build.ps1 | 81 ++++++++++--------- tests/FSharp.Test.Utilities/CompilerAssert.fs | 9 ++- tests/FSharp.Test.Utilities/Utilities.fs | 14 ++++ 3 files changed, 64 insertions(+), 40 deletions(-) diff --git a/eng/Build.ps1 b/eng/Build.ps1 index b085a9163f9..2e45b6ed8bd 100644 --- a/eng/Build.ps1 +++ b/eng/Build.ps1 @@ -51,6 +51,7 @@ param ( [switch]$testCambridge, [switch]$testCompiler, [switch]$testCompilerService, + [switch]$testCompilerComponentTests, [switch]$testFSharpCore, [switch]$testFSharpQA, [switch]$testScripting, @@ -70,48 +71,49 @@ $BuildMessage = "" function Print-Usage() { Write-Host "Common settings:" - Write-Host " -configuration Build configuration: 'Debug' or 'Release' (short: -c)" - Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]" - Write-Host " -deployExtensions Deploy built vsixes" - Write-Host " -binaryLog Create MSBuild binary log (short: -bl)" - Write-Host " -noLog Turn off logging (short: -nolog)" - Write-Host " -excludeCIBinaryLog When running on CI, allow no binary log (short: -nobl)" + Write-Host " -configuration Build configuration: 'Debug' or 'Release' (short: -c)" + Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]" + Write-Host " -deployExtensions Deploy built vsixes" + Write-Host " -binaryLog Create MSBuild binary log (short: -bl)" + Write-Host " -noLog Turn off logging (short: -nolog)" + Write-Host " -excludeCIBinaryLog When running on CI, allow no binary log (short: -nobl)" Write-Host "" Write-Host "Actions:" - Write-Host " -restore Restore packages (short: -r)" - Write-Host " -norestore Don't restore packages" - Write-Host " -build Build main solution (short: -b)" - Write-Host " -rebuild Rebuild main solution" - Write-Host " -pack Build NuGet packages, VS insertion manifests and installer" - Write-Host " -sign Sign our binaries" - Write-Host " -publish Publish build artifacts (e.g. symbols)" - Write-Host " -launch Launch Visual Studio in developer hive" - Write-Host " -help Print help and exit" + Write-Host " -restore Restore packages (short: -r)" + Write-Host " -norestore Don't restore packages" + Write-Host " -build Build main solution (short: -b)" + Write-Host " -rebuild Rebuild main solution" + Write-Host " -pack Build NuGet packages, VS insertion manifests and installer" + Write-Host " -sign Sign our binaries" + Write-Host " -publish Publish build artifacts (e.g. symbols)" + Write-Host " -launch Launch Visual Studio in developer hive" + Write-Host " -help Print help and exit" Write-Host "" Write-Host "Test actions" - Write-Host " -testAll Run all tests" - Write-Host " -testCambridge Run Cambridge tests" - Write-Host " -testCompiler Run FSharpCompiler unit tests" - Write-Host " -testCompilerService Run FSharpCompilerService unit tests" - Write-Host " -testDesktop Run tests against full .NET Framework" - Write-Host " -testCoreClr Run tests against CoreCLR" - Write-Host " -testFSharpCore Run FSharpCore unit tests" - Write-Host " -testFSharpQA Run F# Cambridge tests" - Write-Host " -testScripting Run Scripting tests" - Write-Host " -testVs Run F# editor unit tests" - Write-Host " -testpack Verify built packages" - Write-Host " -officialSkipTests Set to 'true' to skip running tests" + Write-Host " -testAll Run all tests" + Write-Host " -testCambridge Run Cambridge tests" + Write-Host " -testCompiler Run FSharpCompiler unit tests" + Write-Host " -testCompilerService Run FSharpCompilerService unit tests" + Write-Host " -testCompilerComponentTests Run FSharpCompilerService component tests" + Write-Host " -testDesktop Run tests against full .NET Framework" + Write-Host " -testCoreClr Run tests against CoreCLR" + Write-Host " -testFSharpCore Run FSharpCore unit tests" + Write-Host " -testFSharpQA Run F# Cambridge tests" + Write-Host " -testScripting Run Scripting tests" + Write-Host " -testVs Run F# editor unit tests" + Write-Host " -testpack Verify built packages" + Write-Host " -officialSkipTests Set to 'true' to skip running tests" Write-Host "" Write-Host "Advanced settings:" - Write-Host " -ci Set when running on CI server" - Write-Host " -official Set when building an official build" - Write-Host " -bootstrap Build using a bootstrap compiler" - Write-Host " -msbuildEngine Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)." - Write-Host " -procdump Monitor test runs with procdump" - Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build" - Write-Host " -useGlobalNuGetCache Use global NuGet cache." - Write-Host " -noVisualStudio Only build fsc and fsi as .NET Core applications. No Visual Studio required. '-configuration', '-verbosity', '-norestore', '-rebuild' are supported." - Write-Host " -sourceBuild Simulate building for source-build." + Write-Host " -ci Set when running on CI server" + Write-Host " -official Set when building an official build" + Write-Host " -bootstrap Build using a bootstrap compiler" + Write-Host " -msbuildEngine Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)." + Write-Host " -procdump Monitor test runs with procdump" + Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build" + Write-Host " -useGlobalNuGetCache Use global NuGet cache." + Write-Host " -noVisualStudio Only build fsc and fsi as .NET Core applications. No Visual Studio required. '-configuration', '-verbosity', '-norestore', '-rebuild' are supported." + Write-Host " -sourceBuild Simulate building for source-build." Write-Host "" Write-Host "Command line arguments starting with '/p:' are passed through to MSBuild." } @@ -522,6 +524,13 @@ try { TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.UnitTests\FSharp.Compiler.UnitTests.fsproj" -targetFramework $coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.UnitTests\" } + + if ($testCompilerComponentTests) { + TestUsingXUnit -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -noTestFilter $true + TestUsingXUnit -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" + } + + if ($testCompilerService) { TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.Service.Tests\FSharp.Compiler.Service.Tests.fsproj" -targetFramework $desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Service.Tests\" TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.Service.Tests\FSharp.Compiler.Service.Tests.fsproj" -targetFramework $coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Service.Tests\" diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 261e7cd57b8..8bc6921da53 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -91,16 +91,17 @@ type CompilerAssert private () = ctxt.Unload() #else - static let pathToThisDll = Assembly.GetExecutingAssembly().CodeBase - static let adSetup = let setup = new System.AppDomainSetup () - setup.PrivateBinPath <- pathToThisDll + let directory = Path.GetDirectoryName(typeof.Assembly.Location) + setup.ApplicationBase <- directory setup static let executeBuiltApp assembly deps = let ad = AppDomain.CreateDomain((Guid()).ToString(), null, adSetup) - let worker = (ad.CreateInstanceFromAndUnwrap(pathToThisDll, typeof.FullName)) :?> Worker + let worker = + use _ = new AlreadyLoadedAppDomainResolver() + (ad.CreateInstanceFromAndUnwrap(typeof.Assembly.CodeBase, typeof.FullName)) :?> Worker worker.ExecuteTestCase assembly (deps |> Array.ofList) |>ignore #endif diff --git a/tests/FSharp.Test.Utilities/Utilities.fs b/tests/FSharp.Test.Utilities/Utilities.fs index 9c9c62d8503..8cb18a34d04 100644 --- a/tests/FSharp.Test.Utilities/Utilities.fs +++ b/tests/FSharp.Test.Utilities/Utilities.fs @@ -30,6 +30,20 @@ module Utilities = cancellationToken) task.Result + /// Disposable type to implement a simple resolve handler that searches the currently loaded assemblies to see if the requested assembly is already loaded. + type AlreadyLoadedAppDomainResolver () = + let resolveHandler = + ResolveEventHandler(fun _ args -> + let assemblies = AppDomain.CurrentDomain.GetAssemblies() + let assembly = assemblies |> Array.tryFind(fun a -> String.Compare(a.FullName, args.Name,StringComparison.OrdinalIgnoreCase) = 0) + assembly |> Option.defaultValue Unchecked.defaultof + ) + do AppDomain.CurrentDomain.add_AssemblyResolve(resolveHandler) + + interface IDisposable with + member this.Dispose() = AppDomain.CurrentDomain.remove_AssemblyResolve(resolveHandler) + + [] type TargetFramework = | NetStandard20