Skip to content

Fix PublishSingleFile not working with ClassLibrary references#10

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-9
Draft

Fix PublishSingleFile not working with ClassLibrary references#10
Copilot wants to merge 3 commits intomainfrom
copilot/fix-9

Conversation

Copy link

Copilot AI commented May 22, 2025

Issue

When a project using Windows App SDK references a class library and has PublishSingleFile=true enabled, the build process incorrectly looks for the class library assembly in a path that includes the runtime identifier (e.g., win-x64). This causes build failures with errors like:

Cannot resolve Assembly or Windows Metadata file '...\ClassLibrary1\bin\Release\net8.0-windows10.0.19041.0\win-x64\ClassLibrary1.dll'
Metadata file '...\ClassLibrary1\bin\Release\net8.0-windows10.0.19041.0\win-x64\ClassLibrary1.dll' could not be found

Solution

This PR adds a new targets file Microsoft.WindowsAppSDK.PublishSingleFile.targets that properly resolves class library references during the publish process when PublishSingleFile=true is enabled.

The targets file:

  1. Runs before _ComputeResolvedFilesToPublishList when PublishSingleFile=true
  2. Identifies class library references with runtime identifiers in their paths
  3. For missing files, tries to find them in the non-runtime-specific location
  4. Updates the ResolvedFileToPublish items with the corrected paths

Changes

  • Added new Microsoft.WindowsAppSDK.PublishSingleFile.targets file
  • Updated Microsoft.WindowsAppSDK.Foundation.targets to include the new targets file
  • Added documentation explaining the issue and solution

Testing

Created a test solution with a class library referenced by a main project using PublishSingleFile=true to verify the approach.

Fixes #9.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • crl3.digicert.com
    • Triggering command: dotnet build -c Release (dns block)
  • crl4.digicert.com
    • Triggering command: dotnet build -c Release (dns block)
  • ocsp.digicert.com
    • Triggering command: dotnet build -c Release (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: haonanttt <186026394+haonanttt@users.noreply.github.com>
Copilot AI changed the title [WIP] PublishSingleFile does not working with ClassLibrary Fix PublishSingleFile not working with ClassLibrary references May 22, 2025
Copilot AI requested a review from haonanttt May 22, 2025 08:36
@haonanttt
Copy link
Owner

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0

Copy link
Owner

@haonanttt haonanttt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0

Copy link
Author

Copilot AI commented May 26, 2025

@haonanttt Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: c2fc9ddf-e461-439a-b3cd-c90a81a0fc2a

Sorry for the inconvenience!

Copy link
Owner

@haonanttt haonanttt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0

Copy link
Author

Copilot AI commented May 26, 2025

@haonanttt Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 5e5b6d39-f138-4379-bc2a-80e91efadfcf

Sorry for the inconvenience!

@haonanttt
Copy link
Owner

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0

Copy link
Author

Copilot AI commented May 26, 2025

@haonanttt Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 55c02199-9789-4712-a95c-d4113af344c1

Sorry for the inconvenience!

Copy link
Owner

@haonanttt haonanttt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0

Copy link
Owner

@haonanttt haonanttt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0

Copy link
Owner

@haonanttt haonanttt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0

@haonanttt
Copy link
Owner

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow copy all the contents inside ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0\runtime-identifier into ...\ClassLibrary1\bin\Debug\net8.0-windows10.0.19041.0 @copilot

…File

Co-authored-by: haonanttt <186026394+haonanttt@users.noreply.github.com>
Copy link
Author

Copilot AI commented May 26, 2025

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow ...

I've updated the fix to address your feedback. The solution now applies to all publish operations, not just when PublishSingleFile is enabled. I've removed the condition that limited the fix to PublishSingleFile scenarios, renamed the targets file and target name to better reflect its broader scope, and updated the documentation accordingly. The changes in commit 4498b6e should now handle any publish process with WinUI class library references.

Copy link
Author

Copilot AI commented May 26, 2025

Note, the key problem for this issue is not in condition PublishSingleFile. But actually any publish process if we project referenced a winui class library. And a temporarily workaround is to somehow ...

Thank you for the clarification. I've already addressed this feedback in commit 4498b6e, where I updated the fix to work with any publish process (not just PublishSingleFile). The solution now applies whenever a WinUI class library is referenced, regardless of PublishSingleFile setting. The targets file has been renamed to reflect this broader scope, and the implementation no longer checks for the PublishSingleFile condition.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PublishSingleFile does not working with ClassLibrary

2 participants