Skip to content

Commit

Permalink
Work around dotnet/runtime#71027 by using manual runtimeconfig files. (
Browse files Browse the repository at this point in the history
…#2)

The generated ones can result in the consuming application to not be able to load due to hostfxr reordering the frameworks in a way that will cause it to look for hostpolicy in the wrong framework.

Signed-off-by: AraHaan <[email protected]>
  • Loading branch information
AraHaan authored Jul 18, 2022
1 parent 808a497 commit 00cc4db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pkg/sfx/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project>

<ItemGroup>
<FrameworkReference Include="Microsoft.NETCore.App" />
<!-- Try to prevent assemblies that exist in the ASP.NET Core Framework from being included here. -->
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<!-- Work arround https://github.com/dotnet/runtime/issues/71027 by adding NETCore.App last. -->
<FrameworkReference Include="Microsoft.NETCore.App" />
<!-- Required to strong name sign Remora.Discord and it's unsigned dependencies. -->
<PackageReference Include="StrongNamer" Version="*-*" />
<!-- The actual Remora.Discord nuget metapackage. -->
Expand Down
31 changes: 30 additions & 1 deletion pkg/sfx/Remora.Discord.App.Runtime.sfxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Sdk Name="Microsoft.DotNet.Arcade.Sdk" />
<Sdk Name="Microsoft.DotNet.SharedFramework.Sdk" />

Expand All @@ -24,4 +25,32 @@
<PackageIconFullPath>../../images/shark.png</PackageIconFullPath>
</PropertyGroup>

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<!-- override the version specified in Microsoft.NET.Sdk.targets -->
<!-- Work around https://github.com/dotnet/runtime/issues/71027 by adding NETCore.App last in the runtimeconfig file. -->
<!--
There is a problem with the automatically generated runtimeconfig.json
files where it is possible that it can cause the apphost to look for hostpolicy
in the wrong framework directory.

As such we must provide our own runtimeconfig file that gets copied to the
output directory that is manually maintained.
-->
<!-- Caution: Dangerous Hack. -->
<Target
Name="GenerateBuildRuntimeConfigurationFiles"
Condition="'$(GenerateRuntimeConfigurationFiles)' == 'true'"
BeforeTargets="CopyFilesToOutputDirectory">
<Copy
SourceFiles="$(MSBuildThisFileDirectory)runtimeconfig.json"
SkipUnchangedFiles="true"
DestinationFiles="$(ProjectRuntimeConfigFilePath)" />
<!--
For some reason copy creates 2 files instead of just the
copied file with the new name above.
-->
<Delete Files="$(IntermediateOutputPath)runtimeconfig.json" />
</Target>

</Project>
19 changes: 19 additions & 0 deletions pkg/sfx/runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"frameworks": [
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
],
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Reflection.NullabilityInfoContext.IsSupported": true
}
}
}

0 comments on commit 00cc4db

Please sign in to comment.