diff --git a/build/NuSpecs/Microsoft.WindowsAppSDK.ClassLibraryPublish.targets b/build/NuSpecs/Microsoft.WindowsAppSDK.ClassLibraryPublish.targets new file mode 100644 index 00000000..5fdd2c59 --- /dev/null +++ b/build/NuSpecs/Microsoft.WindowsAppSDK.ClassLibraryPublish.targets @@ -0,0 +1,56 @@ + + + + + + + + + + $(PublishDir)%(ResolvedFileToPublish.DestinationSubPath) + + + + + + <_PublishItemsToCheck Include="@(ResolvedFileToPublish)" + Condition="'%(ResolvedFileToPublish.AssetType)' == 'runtime' + AND '%(ResolvedFileToPublish.RuntimeIdentifier)' != '' + AND $([System.String]::Copy('%(ResolvedFileToPublish.SourcePath)').Contains('%(ResolvedFileToPublish.RuntimeIdentifier)'))" /> + + <_MissingRuntimeFiles Include="@(_PublishItemsToCheck)" + Condition="!Exists('%(SourcePath)')" /> + + + + + <_NonRIDSourcePaths Include="@(_MissingRuntimeFiles->'$([System.String]::Copy('%(SourcePath)').Replace('\%(RuntimeIdentifier)\', '\'))')"> + %(_MissingRuntimeFiles.Identity) + + + + + + + + %(Identity) + + + + \ No newline at end of file diff --git a/build/NuSpecs/Microsoft.WindowsAppSDK.Foundation.targets b/build/NuSpecs/Microsoft.WindowsAppSDK.Foundation.targets index 925af86b..21bfd6cd 100644 --- a/build/NuSpecs/Microsoft.WindowsAppSDK.Foundation.targets +++ b/build/NuSpecs/Microsoft.WindowsAppSDK.Foundation.targets @@ -16,6 +16,9 @@ + + + diff --git a/docs/Packaging/WinUI-ClassLibrary-References.md b/docs/Packaging/WinUI-ClassLibrary-References.md new file mode 100644 index 00000000..e4cf5379 --- /dev/null +++ b/docs/Packaging/WinUI-ClassLibrary-References.md @@ -0,0 +1,43 @@ +# WinUI ClassLibrary References During Publish + +## Issue + +When using the Windows App SDK with a project that references a WinUI class library, the build process incorrectly looks for the class library in a path that includes the runtime identifier (e.g., `win-x64`), which causes build failures. This occurs in any publish scenario, including when using `PublishSingleFile=true`. + +For example, if your solution structure is: +``` +Solution + ├── App1 (references ClassLibrary1) + └── ClassLibrary1 +``` + +When publishing App1, you might encounter errors like: +``` +Cannot resolve Assembly or Windows Metadata file 'path\to\ClassLibrary1\bin\Release\net8.0-windows10.0.19041.0\win-x64\ClassLibrary1.dll' +Metadata file 'path\to\ClassLibrary1\bin\Release\net8.0-windows10.0.19041.0\win-x64\ClassLibrary1.dll' could not be found +``` + +## Solution + +The fix implemented in `Microsoft.WindowsAppSDK.ClassLibraryPublish.targets` addresses this issue by correcting the reference paths during the publish process. + +The target does the following: +1. Runs before the `_ComputeResolvedFilesToPublishList` target during any publish operation +2. Identifies class library references that include runtime identifiers in their paths +3. Checks if the files exist at the specified paths +4. For missing files, tries to find them in the non-runtime-specific location +5. Updates the `ResolvedFileToPublish` items with the corrected paths + +## Workaround (prior to this fix) + +If you encounter this issue before updating to a version with this fix, you can: + +1. Create a Blank Project +2. Create a Blank Class Library +3. Add Class Library Reference to Main Project +4. Build +5. Manually modify the Class Library output folder: + - Create a folder named after your runtime identifier (e.g., `win-x64`) in the output directory + - Copy all files from the main output directory into this new folder + +This mimics the file structure expected by the publish process. \ No newline at end of file