Jump to content

New packaging requirements for plugins starting with PDN 4.3 / .NET 5


Recommended Posts

3 hours ago, Rick Brewster said:

What happens if you add in those?

 

That worked.

So it appears that part of the problem may have been that the -d commands should be placed after all of the DLL commands.

I had also used the wrong paths in my previous attempt with those packages.

 

Now I just need to figure out how to make msbuild automate installing those packages if they are not present.

Unfortunately, it is not possible to add a reference to those packages in the project file or install them with the NuGet command line client. Both of those methods produce an error that the DotnetPlatform package type is not supported.

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

32 minutes ago, Rick Brewster said:

The GAC no longer exists, that is not how you deal with shared libraries anymore.

 

In a twisted way, this confirms my other point of "as a developer you don't care about sharing libraries to save memory and RAM".

 

I am a professional developer of 16 years, and I've never [been] bothered to familiarize with the GAC or any of that stuff. You just reference a DLL in your project, it gets copied alongside your DLLs, you ship your own copies of the DLLs you need, and you never bother to try and make anything "shared" or access something that could probably be "shared" apart from the default runtime environment... Hence I didn't even know they abolished the GAC concept. But they probably did it for exactly that reason... managing 20+ of versions of a file which are all called "System.Windows.dll" in a "common" folder and have everyone who asks for "System.Windows" with an arbitrary version [range] get the right version and load all that conflict-free in an interoperable manner is a nightmare task. So we gave up on that front and that's probably a good thing for keeping everything smoothly running - everybody gets served exactly what they expected and nothing else.

Link to comment
Share on other sites

It turns out that NuGet installs those dotnet packages, even though it exits with an error message.

The final command I am using in PSFilterPdn to trim CommunityToolkit.HighPerformace and TerraFX.Interop.Windows is below.

 

<ItemGroup>
  <PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.1" />
  <PackageReference Include="MessagePack" Version="2.5.124" />
  <PackageReference Include="NuGet.CommandLine" Version="6.6.1">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  </PackageReference>
  <PackageReference Include="TerraFX.Interop.Windows" Version="10.0.22621.2" />
</ItemGroup>
<PropertyGroup>
  <!-- This is required for MSBuild to copy the refrenced NuGet packages to the build output folder -->
  <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  <!-- Set the .NET runtime information -->
  <CurrentRuntime>$(TargetFramework.Replace('-windows', ''))</CurrentRuntime>
  <CurrentRuntimeVersion>$(BundledNETCoreAppPackageVersion)</CurrentRuntimeVersion>
  <CurrentRID>$(NETCoreSdkRuntimeIdentifier)</CurrentRID>
  <!-- Set Path Variables -->
  <PdnRoot>D:\Program Files\paint.net</PdnRoot>
  <SDKRoot>$(NetCoreRoot)sdk\$(NETCoreSdkVersion)</SDKRoot>
  <illink>$(SDKRoot)\Sdks\Microsoft.NET.ILLink.Tasks\tools\$(CurrentRuntime)\illink.dll</illink>
  <NugetSourceRoot>$(UserProfile)\.nuget\packages</NugetSourceRoot>
  <NETCoreAppPackageName>Microsoft.NETCore.App.Runtime.$(CurrentRID)</NETCoreAppPackageName>
  <NETCoreAppDir>$(NugetSourceRoot)\$(NETCoreAppPackageName)\$(CurrentRuntimeVersion)\runtimes\$(CurrentRID)\lib\$(CurrentRuntime)</NETCoreAppDir>
  <WindowsDesktopPackageName>Microsoft.WindowsDesktop.App.Runtime.$(CurrentRID)</WindowsDesktopPackageName>
  <WindowsDesktopAppDir>$(NugetSourceRoot)\$(WindowsDesktopPackageName)\$(CurrentRuntimeVersion)\runtimes\$(CurrentRID)\lib\$(CurrentRuntime)</WindowsDesktopAppDir>
  <!-- Set a few additional properties -->
  <!-- All of these warnings are related to the DLLs that are not being trimmed -->
  <ILLinkIgnoredWarnings>IL2026;IL2028;IL2034;IL2046;IL2050;IL2055;IL2057;IL2058;IL2059;IL2060;IL2062;IL2065;IL2066;IL2067;IL2070;IL2072;IL2075;IL2077;IL2080;IL2087;IL2088;IL2090;IL2091;IL2092;IL2093;IL2094;IL2096;IL2104;IL2111;IL2118;IL2121</ILLinkIgnoredWarnings>
  <ILLinkFolderName>link</ILLinkFolderName>
</PropertyGroup>
<ItemGroup>
  <!-- The SourceFile items will be copied to the output folder -->
  <SourceFile Include="$(TargetPath)" />
  <SourceFile Include="$(TargetDir)$(TargetName).pdb" />
  <SourceFile Include="$(TargetDir)$(TargetName).deps.json" />
  <SourceFile Include="$(TargetDir)MessagePack.dll" />
  <SourceFile Include="$(TargetDir)MessagePack.Annotations.dll" />
  <!-- The FastDebug configuration does not call ILLink to trim the DLLs -->
  <SourceFile Condition="'$(Configuration)' == 'FastDebug'" Include="$(TargetDir)CommunityToolkit.HighPerformance.dll" />
  <SourceFile Condition="'$(Configuration)' == 'FastDebug'" Include="$(TargetDir)TerraFX.Interop.Windows.dll" />
  <SourceFile Condition="'$(Configuration)' != 'FastDebug'" Include="$(TargetDir)$(ILLinkFolderName)\CommunityToolkit.HighPerformance.dll" />
  <SourceFile Condition="'$(Configuration)' != 'FastDebug'" Include="$(TargetDir)$(ILLinkFolderName)\TerraFX.Interop.Windows.dll" />
  <OutputDirFiles Include="$(TargetDir)output\*.*" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <!-- 1st Step: Install the .NET packages that are required for trimming -->
  <!-- All errors are ignored because NuGet reports that is doesn't support the package type after installing it -->
  <Exec Condition="'$(Configuration)' != 'FastDebug' And !Exists('$(NETCoreAppDir)')" Command="$(PkgNuGet_CommandLine)\tools\NuGet.exe install $(NETCoreAppPackageName) -Version $(CurrentRuntimeVersion) -OutputDirectory $(NugetSourceRoot)" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" />
  <Exec Condition="'$(Configuration)' != 'FastDebug' And !Exists('$(WindowsDesktopAppDir)')" Command="$(PkgNuGet_CommandLine)\tools\NuGet.exe install $(WindowsDesktopPackageName) -Version $(CurrentRuntimeVersion) -OutputDirectory $(NugetSourceRoot)" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" />
  <!-- 2nd Step: Trimming with ILLink -->
  <Exec Condition="'$(Configuration)' != 'FastDebug'" Command="dotnet exec &quot;$(illink)&quot; -a &quot;$(TargetPath)&quot; all &#45;&#45;trim-mode copy &#45;&#45;action copy &#45;&#45;action link &quot;CommunityToolkit.HighPerformance&quot; &#45;&#45;action link &quot;TerraFX.Interop.Windows&quot;  -d $(TargetDir) -d $(NETCoreAppDir) -d $(WindowsDesktopAppDir) &#45;&#45;skip-unresolved -out &quot;$(TargetDir)$(ILLinkFolderName)&quot; &#45;&#45;nowarn $(ILLinkIgnoredWarnings)" />
  <!-- 3rd Step: Copy all dependencies to the output directory -->
  <Copy SourceFiles="@(SourceFile)" DestinationFolder="$(TargetDir)output" OverwriteReadOnlyFiles="true" SkipUnchangedFiles="true" />
  <!-- 4th Step: Delete the ILLink output directory -->
  <RemoveDir Condition="'$(Configuration)' != 'FastDebug'" Directories="$(TargetDir)$(ILLinkFolderName)\" />
  <!-- 5th Step: Copy the output folder to the Paint.NET Effects folder -->
  <Copy SourceFiles="@(OutputDirFiles)" DestinationFolder="$(PdnRoot)\Effects\PSFilterPdn" OverwriteReadOnlyFiles="true" SkipUnchangedFiles="true" />
</Target>

 

Because trimming takes a significant amount of time it is skipped for the FastDebug project configuration, I copied this from CodeLab's build process.

The appropriate Microsoft.NETCore.App.Runtime and Microsoft.WindowsDesktop.App.Runtime packages will be downloaded and installed if necessary.

 

After trimming, the trimmed files are copied into an output folder and the ILLink trimming folder is deleted.

This step could probably be skipped and replaced with step 5, but it simplified the process of verifying that things were working correctly.

  • Like 1

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...