microsoft / microsoft/WindowsAppSDK

WinUI build/publish fails due to WindowsAppSDKSelfContained misapplied to referenced project (2.0-prev1)

Open
#6,365 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-MSIXBuildTools needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

Describe the bug

When publishing a WinUI application using dotnet publish, the process fails if the executable project references another WinUI class library project and WindowsAppSDKSelfContained is set to true.

During publishing, the build system appears to propagate or evaluate the WindowsAppSDKSelfContained setting for the referenced class library as well, which leads to the following error:

WindowsAppSDKSelfContained should not be applied to a class library

This results in the publish operation failing, even though the setting is only intended for the executable project.

Steps to reproduce the bug
  1. Create two projects WinUI App + WinUI lib
  2. Add a reference to WinUI lib to WinUI App
  3. Run command for the WinUI App dotnet publish --self-contained true -p:RuntimeIdentifier=win-x64 -p:WindowsAppSDKSelfContained=true

Error:

C:\temp\winui\exe>dotnet publish --self-contained true -p:RuntimeIdentifier=win-x64 -p:WindowsAppSDKSelfContained=true
Restore complete (0.7s)
  lib net10.0-windows10.0.19041.0 win-x64 failed with 1 error(s) (0.6s) → C:\temp\winui\lib\bin\Release\net10.0-windows10.0.19041.0\win-x64\lib.dll
    C:\Users\xy\.nuget\packages\microsoft.windowsappsdk.base\2.0.2-preview\buildTransitive\Microsoft.WindowsAppSDK.Base.targets(20,9): **error WindowsAppSDKSelfContained should not be applied to a class library.**
Expected behavior

The build should pass and the WindowsAppSDKSelfContained shouldn't be applied for the lib projects.

Screenshots

No response

NuGet package version

2.0.0-prev1

Packaging type

No response

Windows version

No response

IDE

No response

Additional context

If I publish it through a profile file then it works:

<?xml version="1.0" encoding="UTF-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishProtocol>FileSystem</PublishProtocol>
    <Platform>x64</Platform>
    <RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x64</RuntimeIdentifier>
    <RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x64</RuntimeIdentifier>
    <PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>False</PublishSingleFile>
    <PublishReadyToRun>True</PublishReadyToRun>
    <PublishTrimmed>True</PublishTrimmed>
    <TrimmMode>partial</TrimmMode>
    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  </PropertyGroup>
</Project>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the publish command with a WinUI app referencing a WinUI class library, then inspect Microsoft.WindowsAppSDK.Base.targets at the reported line 20. Verify how WindowsAppSDKSelfContained is evaluated for the referenced project; done means the class library is not given that setting and the app publish completes successfully.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.