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
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 committed Jul 18, 2022
1 parent bd23eba commit 65fdc39
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
26 changes: 26 additions & 0 deletions pkg/sfx/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
<OverridePackageId>$(SharedFrameworkName).Runtime.$(RuntimeIdentifier)</OverridePackageId>
<PlatformPackageType>RuntimePack</PlatformPackageType>
<ArchiveName>efcore-runtime</ArchiveName>
<!-- 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.
-->
<GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

<PropertyGroup Condition="$(MSBuildProjectName.Contains('.Ref'))">
Expand All @@ -26,4 +36,20 @@
<ArchiveName>efcore-targeting-pack</ArchiveName>
</PropertyGroup>

<!-- Caution: Dangerous Hack. -->
<Target
Name="CopyManualRuntimeConfigFile"
Condition="'$(GenerateRuntimeConfigurationFiles)' == 'false' AND !$(MSBuildProjectName.Contains('.Ref'))"
BeforeTargets="CopyFilesToOutputDirectory">
<Copy
SourceFiles="$(MSBuildThisFileDirectory)runtimeconfig.json"
SkipUnchangedFiles="true"
DestinationFiles="$(TargetDir)$(AssemblyName).runtimeconfig.json" />
<!--
For some reason copy creates 2 files instead of just the
copied file with the new name above.
-->
<Delete Files="$(TargetDir)runtimeconfig.json" />
</Target>

</Project>
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" />
<!-- The actual EntityFrameworkCore nuget packages. -->
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.6" />
Expand Down
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 65fdc39

Please sign in to comment.