Skip to content

Failed to resolve assembly PresentationFramework with .Net 8 #70

Description

@Eivind98

I have a solution with multiple projects which import from the same .csproj file where the difference is the framework changes from net481 to net8.0-windows. I ran into a problem where PresentationFramework doesn't resolve in the net8.0-windows framework but works fine with the net481 framework.

Package Reference:

I found a work around that programmatically finds the missing library path and adds it to LibraryPath:

<!-- Finding the path to PresentationFramework to help ILRepack to resolve dependncies for .net 8-->
<UsingTask TaskName="FindRefPackPath" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
  <ParameterGroup>
    <BasePath ParameterType="System.String" Required="true" />
    <LatestPath Output="true" ParameterType="System.String" />
  </ParameterGroup>
  <Task>
    <Using Namespace="System.IO" />
    <Code Type="Fragment" Language="cs">
      <![CDATA[
    string[] dirs = Directory.GetDirectories(BasePath)
        .Where(d => Path.GetFileName(d).StartsWith("8"))
        .OrderBy(v => v)
        .ToArray();

    if (dirs.Length > 0)
    {
        LatestPath = Path.Combine(dirs[dirs.Length - 1], "ref", "net8.0");
    }
    ]]>
    </Code>
  </Task>
</UsingTask>

<Target Name="ResolveDesktopRefPath" BeforeTargets="Build">
  <FindRefPackPath BasePath="$(ProgramFiles)\dotnet\packs\Microsoft.WindowsDesktop.App.Ref" >
    <Output TaskParameter="LatestPath" PropertyName="NetSdkRefPath" />
  </FindRefPackPath>

  <Message Text="Resolved NetSdkRefPath: $(NetSdkRefPath)" Importance="high" />
</Target>

<Target Name="ILRepacker" AfterTargets="Build">
  <ItemGroup>
    <InputAssemblies Include="$(TargetPath)" />
    <InputAssemblies Include="$(TargetDir)File1.dll" />
    <InputAssemblies Include="$(TargetDir)File2.dll" />
    <InputAssemblies Include="$(TargetDir)File3.dll" />
  </ItemGroup>

  <ILRepack
      Parallel="true"
      Internalize="false"
      InputAssemblies="@(InputAssemblies)"
      TargetKind="Dll"
      OutputFile="$(OutputPath)$(AssemblyName).dll"
      LibraryPath="$(NetSdkRefPath)"
      />
</Target>

This workaround helps, but I wouldn't expect to have to manually resolve the Library path. Shouldn't ILRepack automatically find these references?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions