-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Dipping toes into linker friendliness #24458
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
Changes from all commits
c8456e8
fa0577c
8c11b8d
c69d711
c47a622
a3cf88e
603a8da
845af6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.AspNetCore.Hosting.Internal | ||
{ | ||
internal static class StartupLinkerOptions | ||
{ | ||
// We're going to keep all public constructors and public methods on Startup classes | ||
public const DynamicallyAccessedMemberTypes Accessibility = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicMethods; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ public virtual Task<PublishedApplication> Publish(DeploymentParameters deploymen | |
// avoids triggering builds of dependencies of the test app which could cause issues like https://github.com/dotnet/arcade/issues/2941 | ||
+ $" --no-dependencies" | ||
+ $" /p:TargetArchitecture={deploymentParameters.RuntimeArchitecture}" | ||
+ " --no-restore"; | ||
+ (deploymentParameters.RestoreDependencies ? "" : " --no-restore"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall no-restore is required for all tests on Helix because the test assets need to be pre-built before publishing to helix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works fine on helix as far as I could tell. |
||
|
||
if (deploymentParameters.ApplicationType == ApplicationType.Standalone) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Server.IntegrationTesting; | ||
using Microsoft.AspNetCore.Testing; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Hosting.FunctionalTests | ||
{ | ||
public class LinkedApplicationTests : LoggedTest | ||
{ | ||
[Fact] | ||
public async Task LinkedApplicationWorks() | ||
{ | ||
using (StartLog(out var loggerFactory)) | ||
{ | ||
var logger = loggerFactory.CreateLogger("LinkedApplicationWorks"); | ||
|
||
// https://github.com/dotnet/aspnetcore/issues/8247 | ||
#pragma warning disable 0618 | ||
var applicationPath = Path.Combine(TestPathUtilities.GetSolutionRootDirectory("Hosting"), "test", "testassets", | ||
"BasicLinkedApp"); | ||
#pragma warning restore 0618 | ||
|
||
var deploymentParameters = new DeploymentParameters( | ||
applicationPath, | ||
ServerType.Kestrel, | ||
RuntimeFlavor.CoreClr, | ||
RuntimeArchitecture.x64) | ||
{ | ||
TargetFramework = Tfm.Net50, | ||
RuntimeArchitecture = RuntimeArchitecture.x64, | ||
ApplicationType = ApplicationType.Standalone, | ||
PublishApplicationBeforeDeployment = true, | ||
RestoreDependencies = true, | ||
StatusMessagesEnabled = false | ||
}; | ||
|
||
using var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory); | ||
|
||
var result = await deployer.DeployAsync(); | ||
|
||
// The app should have started up | ||
Assert.False(deployer.HostProcess.HasExited); | ||
|
||
var response = await RetryHelper.RetryRequest(() => result.HttpClient.GetAsync("/"), logger, retryCount: 10); | ||
var body = await response.Content.ReadAsStringAsync(); | ||
|
||
Assert.Equal("Hello World", body); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<PublishTrimmed>true</PublishTrimmed> | ||
<TrimMode>link</TrimMode> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.AspNetCore.Hosting" /> | ||
<Reference Include="Microsoft.Extensions.Hosting" /> | ||
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<TrimmerRootDescriptor Include="Linker.xml" /> | ||
</ItemGroup> | ||
|
||
<!-- Link all assemblies --> | ||
<Target Name="EnsureAllAssembliesAreLinked" BeforeTargets="PrepareForILLink"> | ||
<ItemGroup> | ||
<ManagedAssemblyToLink> | ||
<TrimMode>link</TrimMode> | ||
</ManagedAssemblyToLink> | ||
<!-- Root this project assembly --> | ||
<TrimmerRootAssembly Include="$(TargetName)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- See: https://github.com/mono/linker/blob/master/src/linker/README.md#syntax-of-xml-descriptor --> | ||
<linker> | ||
<assembly fullname="Microsoft.Extensions.Hosting"> | ||
<type fullname="Microsoft.Extensions.Hosting.Internal.ApplicationLifetime" /> | ||
<type fullname="Microsoft.Extensions.Hosting.Internal.ConsoleLifetime" /> | ||
<type fullname="Microsoft.Extensions.Hosting.ConsoleLifetimeOptions" /> | ||
<type fullname="Microsoft.Extensions.Hosting.Internal.Host" /> | ||
<type fullname="Microsoft.Extensions.Hosting.HostOptions" /> | ||
</assembly> | ||
<assembly fullname="Microsoft.Extensions.Logging"> | ||
<type fullname="Microsoft.Extensions.Logging.LoggerFactory" /> | ||
</assembly> | ||
<assembly fullname="Microsoft.Extensions.Logging.Configuration"> | ||
<type fullname="Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory" /> | ||
<type fullname="Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigureOptions`2" /> | ||
<type fullname="Microsoft.Extensions.Logging.Configuration.LoggerProviderOptionsChangeTokenSource`2" /> | ||
<type fullname="Microsoft.Extensions.Logging.Configuration.LoggerProviderConfiguration`1" /> | ||
</assembly> | ||
<assembly fullname="Microsoft.Extensions.Logging.Console" preserve="all" /> | ||
<assembly fullname="Microsoft.AspNetCore.Hosting"> | ||
<type fullname="Microsoft.AspNetCore.Hosting.GenericWebHostApplicationLifetime" /> | ||
<type fullname="Microsoft.AspNetCore.Http.DefaultHttpContextFactory" /> | ||
<type fullname="Microsoft.AspNetCore.Hosting.Builder.ApplicationBuilderFactory" /> | ||
<type fullname="Microsoft.AspNetCore.Hosting.GenericWebHostService" /> | ||
<type fullname="Microsoft.AspNetCore.Hosting.GenericWebHostServiceOptions" /> | ||
</assembly> | ||
<assembly fullname="Microsoft.AspNetCore.Http"> | ||
<type fullname="Microsoft.AspNetCore.Http.MiddlewareFactory" /> | ||
</assembly> | ||
<assembly fullname="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"> | ||
<type fullname="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory" /> | ||
<type fullname="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions" /> | ||
</assembly> | ||
<assembly fullname="Microsoft.AspNetCore.Server.Kestrel.Core"> | ||
<type fullname="Microsoft.AspNetCore.Server.Kestrel.Core.Internal.KestrelServerOptionsSetup" /> | ||
<type fullname="Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer" /> | ||
</assembly> | ||
<assembly fullname="Microsoft.Extensions.Options"> | ||
<type fullname="Microsoft.Extensions.Options.OptionsCache`1" /> | ||
<type fullname="Microsoft.Extensions.Options.OptionsFactory`1" /> | ||
<type fullname="Microsoft.Extensions.Options.OptionsMonitor`1" /> | ||
<type fullname="Microsoft.Extensions.Options.OptionsManager`1" /> | ||
</assembly> | ||
</linker> |
Uh oh!
There was an error while loading. Please reload this page.