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
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ public abstract class DependencyResolutionBase

public abstract class SharedTestStateBase : TestArtifact
{
protected string BuiltDotnetPath { get; }

public RepoDirectoriesProvider RepoDirectories { get; }

private static string GetBaseDir(string name)
{
string baseDir = Path.Combine(TestArtifactsPath, name);
Expand All @@ -25,20 +21,18 @@ private static string GetBaseDir(string name)
public SharedTestStateBase()
: base(GetBaseDir("dependencyResolution"))
{
BuiltDotnetPath = Path.Combine(TestArtifactsPath, "sharedFrameworkPublish");
RepoDirectories = new RepoDirectoriesProvider(builtDotnet: BuiltDotnetPath);
}

public DotNetBuilder DotNet(string name)
{
return new DotNetBuilder(Location, BuiltDotnetPath, name);
return new DotNetBuilder(Location, RepoDirectoriesProvider.Default.BuiltDotnet, name);
}

public TestApp CreateFrameworkReferenceApp(string fxName, string fxVersion)
public TestApp CreateFrameworkReferenceApp(string fxName, string fxVersion, Action<NetCoreAppBuilder> customizer = null)
{
// Prepare the app mock - we're not going to run anything really, so we just need the basic files
TestApp testApp = CreateTestApp(Location, "FrameworkReferenceApp");
testApp.PopulateFrameworkDependent(fxName, fxVersion);
testApp.PopulateFrameworkDependent(fxName, fxVersion, customizer);
return testApp;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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.IO;
using Microsoft.DotNet.Cli.Build;
using Microsoft.DotNet.Cli.Build.Framework;
using Xunit;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
{
public class DepsFile : DependencyResolutionBase, IClassFixture<DepsFile.SharedTestState>
{
private readonly SharedTestState sharedState;

public DepsFile(SharedTestState sharedState)
{
this.sharedState = sharedState;
}

[Fact]
public void NoDepsJson()
{
// Without .deps.json, all assemblies in the app's directory are added to the TPA
// and the app's directory is added to the native library search path
TestApp app = sharedState.FrameworkReferenceApp;
sharedState.DotNetWithNetCoreApp.Exec(app.AppDll)
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveResolvedAssembly(Path.Combine(app.Location, $"{SharedTestState.DependencyName}.dll"))
.And.HaveResolvedNativeLibraryPath(app.Location);
}

[Fact]
public void SeparateDepsJson()
{
// For framework-dependent apps, the probing directories are:
// - The directory where the .deps.json is
// - Any framework directory
// Dependency should resolve relative to the .deps.json directory without checking for file existence
string dependencyPath = Path.Combine(Path.GetDirectoryName(sharedState.DepsJsonPath), $"{SharedTestState.DependencyName}.dll");
sharedState.DotNetWithNetCoreApp.Exec("exec", Constants.DepsFile.CommandLineArgument, sharedState.DepsJsonPath, sharedState.FrameworkReferenceApp.AppDll)
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveResolvedAssembly(dependencyPath);
}

public class SharedTestState : DependencyResolutionBase.SharedTestStateBase
{
public DotNetCli DotNetWithNetCoreApp { get; }

public TestApp FrameworkReferenceApp { get; }

public const string DependencyName = "Dependency";

public string DepsJsonPath { get; }

public SharedTestState()
{
DotNetWithNetCoreApp = DotNet("WithNetCoreApp")
.AddMicrosoftNETCoreAppFrameworkMockCoreClr(RepoDirectoriesProvider.Default.MicrosoftNETCoreAppVersion)
.Build();

FrameworkReferenceApp = CreateFrameworkReferenceApp(MicrosoftNETCoreApp, RepoDirectoriesProvider.Default.MicrosoftNETCoreAppVersion, b => b
.WithProject(DependencyName, "1.0.0", p => p
.WithAssemblyGroup(null, g => g.WithAsset($"{DependencyName}.dll"))));

var depsDir = Path.Combine(Location, "deps");
Directory.CreateDirectory(depsDir);
DepsJsonPath = Path.Combine(depsDir, Path.GetFileName(FrameworkReferenceApp.DepsJson));
File.Move(FrameworkReferenceApp.DepsJson, DepsJsonPath);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -104,7 +104,7 @@ protected override void CustomizeDotNetWithNetCoreApp(DotNetBuilder builder)
HighWare,
"1.1.1",
runtimeConfig => runtimeConfig.WithFramework(MicrosoftNETCoreApp, "4.0.0"),
path => NetCoreAppBuilder.ForNETCoreApp(HighWare, RepoDirectories.TargetRID)
path => NetCoreAppBuilder.ForNETCoreApp(HighWare, RepoDirectoriesProvider.Default.TargetRID)
.WithProject(HighWare, "1.1.1", p => p
.WithAssemblyGroup(null, g => g
.WithAsset(TestAssemblyWithNoVersions + ".dll")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public SharedTestState() : base()
protected void UseFallbacksFromBuiltDotNet(NetCoreAppBuilder builder)
{
IReadOnlyList<RuntimeFallbacks> fallbacks;
string depsJson = Path.Combine(new DotNetCli(BuiltDotnetPath).GreatestVersionSharedFxPath, $"{Constants.MicrosoftNETCoreApp}.deps.json");
string depsJson = Path.Combine(new DotNetCli(RepoDirectoriesProvider.Default.BuiltDotnet).GreatestVersionSharedFxPath, $"{Constants.MicrosoftNETCoreApp}.deps.json");
using (FileStream fileStream = File.Open(depsJson, FileMode.Open))
using (DependencyContextJsonReader reader = new DependencyContextJsonReader())
{
Expand Down
84 changes: 0 additions & 84 deletions src/installer/tests/HostActivation.Tests/PortableAppActivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,6 @@ public void Muxer_activation_of_Apps_with_AltDirectorySeparatorChar()
.And.HaveStdOutContaining("Hello World");
}

// https://github.com/dotnet/runtime/issues/3654
[Fact(Skip = "The 3.0 SDK copies NuGet references to the output by default now for executable projects, so this no longer fails.")]
public void Muxer_Exec_activation_of_Build_Output_Portable_DLL_with_DepsJson_Local_and_RuntimeConfig_Remote_Without_AdditionalProbingPath_Fails()
{
var fixture = sharedTestState.PortableAppFixture_Built
.Copy();

var runtimeConfig = MoveRuntimeConfigToSubdirectory(fixture);

var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;

dotnet.Exec("exec", "--runtimeconfig", runtimeConfig, appDll)
.CaptureStdErr()
.CaptureStdOut()
.Execute(expectedToFail: true)
.Should().Fail();
}

// https://github.com/dotnet/runtime/issues/3654
[Fact(Skip = "The 3.0 SDK copies NuGet references to the output by default now for executable projects, so this no longer fails.")]
public void Muxer_Exec_activation_of_Build_Output_Portable_DLL_with_DepsJson_Local_and_RuntimeConfig_Remote_With_AdditionalProbingPath_Succeeds()
Expand Down Expand Up @@ -156,34 +137,6 @@ public void Muxer_Activation_With_Templated_AdditionalProbingPath_Succeeds()
.And.HaveStdErrContaining($"Adding tpa entry: {Path.Combine(store_path, fixture.RepoDirProvider.BuildArchitecture, fixture.Framework)}");
}

[Fact]
public void Muxer_Exec_activation_of_Build_Output_Portable_DLL_with_DepsJson_Remote_and_RuntimeConfig_Local_Succeeds()
{
var fixture = sharedTestState.PortableAppFixture_Built
.Copy();

// Move the .deps.json to a subdirectory, note that in this case we have to move all of the app's dependencies
// along with it - in this case Newtonsoft.Json.dll
// For framework dependent apps (dotnet build produces those) the probing directories are:
// - The directory where the .deps.json is
// - Any framework directory
var depsJson = MoveDepsJsonToSubdirectory(fixture);
File.Move(
Path.Combine(Path.GetDirectoryName(fixture.TestProject.AppDll), "Newtonsoft.Json.dll"),
Path.Combine(Path.GetDirectoryName(depsJson), "Newtonsoft.Json.dll"));

var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;

dotnet.Exec("exec", "--depsfile", depsJson, appDll)
.CaptureStdErr()
.CaptureStdOut()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World");

}

[Fact]
public void Muxer_activation_of_Publish_Output_Portable_DLL_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
{
Expand Down Expand Up @@ -228,24 +181,6 @@ public void Muxer_Exec_activation_of_Publish_Output_Portable_DLL_with_DepsJson_L
.And.HaveStdOutContaining("Hello World");
}

[Fact]
public void Muxer_Exec_activation_of_Publish_Output_Portable_DLL_with_DepsJson_Remote_and_RuntimeConfig_Local_Fails()
{
var fixture = sharedTestState.PortableAppFixture_Published
.Copy();

var depsJson = MoveDepsJsonToSubdirectory(fixture);

var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;

dotnet.Exec("exec", "--depsfile", depsJson, appDll)
.CaptureStdErr()
.CaptureStdOut()
.Execute(expectedToFail: true)
.Should().Fail();
}

[Fact]
public void AppHost_FrameworkDependent_Succeeds()
{
Expand Down Expand Up @@ -639,25 +574,6 @@ public void AppHost_GUI_FrameworkDependent_DisabledGUIErrors_DialogNotShown()
}
}

private string MoveDepsJsonToSubdirectory(TestProjectFixture testProjectFixture)
{
var subdirectory = Path.Combine(testProjectFixture.TestProject.ProjectDirectory, "d");
if (!Directory.Exists(subdirectory))
{
Directory.CreateDirectory(subdirectory);
}

var destDepsJson = Path.Combine(subdirectory, Path.GetFileName(testProjectFixture.TestProject.DepsJson));

if (File.Exists(destDepsJson))
{
File.Delete(destDepsJson);
}
File.Move(testProjectFixture.TestProject.DepsJson, destDepsJson);

return destDepsJson;
}

private string MoveRuntimeConfigToSubdirectory(TestProjectFixture testProjectFixture)
{
var subdirectory = Path.Combine(testProjectFixture.TestProject.ProjectDirectory, "r");
Expand Down
5 changes: 5 additions & 0 deletions src/installer/tests/TestUtils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public static class AdditionalDeps
public const string CommandLineArgument = "--additional-deps";
}

public static class DepsFile
{
public const string CommandLineArgument = "--depsfile";
}

public static class RollForwardToPreRelease
{
public const string EnvironmentVariable = "DOTNET_ROLL_FORWARD_TO_PRERELEASE";
Expand Down