maui: With UseMaui = true in class library I get a '"CopyLocalFilesOutputGroup" does not exist' error
Description
When I create a class library for reusable maui components and add <UseMaui>true</UseMaui> to the csproj I get this error:
C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.300-rc.2.5513\Sdk\WinUI.NetCore.targets(188,5): error MSB4057: The target "CopyLocalFilesOutputGroup" does not exist in the project. C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.300-rc.2.5513\Sdk\WinUI.NetCore.targets
Used rc2 and VS preview 5
I am not sure if I am supposed to use <UseMaui>true</UseMaui> for this purpose. I would like to know the alternative way if there is one. Still there may have to be a better error in this situation.
Screenshot of the situation:

Minimal reproduction: CopyLocalFilesOutputGroup-does-not-exist.zip
Steps to Reproduce
- Create a new maui app
- Create a new class library
- Add <UseMaui>true</UseMaui> to the csproj of the class library
- Add a reference to the class library in the maui app
- Compile.
Version with bug
Release Candidate 2
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
It is a compile problem so I guess it affects all platforms with RC 2. I compiled on Windows.
Did you find any workaround?
No
Relevant log output
Build started...
1>------ Build started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
1>You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>ClassLibrary1 -> C:\Users\pauld\source\repos\MauiApp3\ClassLibrary1\bin\Debug\net6.0\ClassLibrary1.dll
2>------ Build started: Project: MauiApp3, Configuration: Debug Any CPU ------
2>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
2>MauiApp3 -> C:\Users\pauld\source\repos\MauiApp3\MauiApp3\bin\Debug\net6.0-windows10.0.19041.0\win10-x64\MauiApp3.dll
2>C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.300-rc.2.5513\Sdk\WinUI.NetCore.targets(188,5): error MSB4057: The target "CopyLocalFilesOutputGroup" does not exist in the project. C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.300-rc.2.5513\Sdk\WinUI.NetCore.targets
2>Done building project "ClassLibrary1.csproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 42 (11 by maintainers)
Yeah. 😦 Windows errors are crazy hard to debug. Usually when this happens I check the C++ and CLR check boxes in the Exception Settings window - not perfect, but catches more exceptions (be warned WinUI throws a bit but you have to continue through as they are caught elsewhere):
At this moment I use:
these are settings in my Windows project. But still no succes, I am getting a little frustrated now. Everything worked till de Release Candidates.
When RC1 was released I had some problems but I fixed them. But since RC2 (when you think it should getting better) the project can not be build.
This does not work if you have a class library that uses only
<UseMaui>true</UseMaui>(no platform specific code) and is referenced by a Maui application. The building of the library then fails withC:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.300-rc.2.5513\Sdk\WinUI.NetCore.targets(188,5): error MSB4057: The target "CopyLocalFilesOutputGroup" does not exist in the project.Repro steps:
Build the project. The build of the library will fail with the above error but only if it is referenced from the main project. If it is not referenced the build succeeds.
I think the fix has simply not in the rc.3 release. As I posted in the MR thread:
A little more experimentation on a Windows box, and I’ve found that the error only occurs when both of the following are true:
<UseMaui>or<UseMauiCore>)<TargetFrameworks>instead of<TargetFramework>It does not seem to matter whether the class library is targeting one or more platforms, or which platform it is. It also doesn’t seem to matter whether the app is targeting Windows or Android or something else - but the build error only occurs when building on Windows.
Maybe this has slipped away. The problem happens under following circumstances:
Then the problem is reported for each of the libraries that have only the net6.0 target
I had the same problem.
I Started with a single project then I decided to split it into project and library.
It took me some time but close to end I was stuck with the same message …
The problem was that when the library was created it automatically used
$(TargetFrameworks);net6.0-windows10.0.19041.0
while the project was using
$(TargetFrameworks);net6.0-windows10.0.19041
Deleted the .0 then it build and worked fine 😃
Hope it helps 😃
I have been digging some more and there are a few issues that all come together. So the real issue why it is broken is still the fact that the WinUI targets assume the TFM is exactly the same.
However, the one difference before is that the targets used to be located in the WindowsAppSDK nuget, so when the app called a specific target in the library that was NOT winui, it actually fell through to a dummy target. However, due to a few bugs in certain situations, we moved some of the targets from the nuget into MAUI temporarily. This fixes a few issues with resources and packaging, but exposed this issue.
We have a condition now in the targets that was checking if the library was a maui app and a windows TFM, however, because the app lies to us and tells us we are a windows library, it starts down the wrong path.
I have a PR that should make things much better: #6767
But, the current workaround is to make sure you have the windows TFM and then you might also have to set
EnablePreviewMsixTooling=TrueandGenerateLibraryLayout=True.I believe this is an issue with the Windows App SDK that assumes that the class libraries have the same windows TargetFramework as the app project. It doesn’t do a compatible check.
If the app is net6.0-windows10.0.19041.0, then that tfm must exist exactly in the class library.
It even matters with the last .0 in the version as the app just says get the bits using my tfm.
I think the solution would be to also add the windows tfm to the class library.
I’ll be trying to repro this on a Windows only project and log an issue with them.
I have tried the same, also with IncludeCopyLocalFilesOutputGroup, but that did not change anything for me