maui
                                
                                 maui copied to clipboard
                                
                                    maui copied to clipboard
                            
                            
                            
                        Can't publish a Maui app that references a class library on Windows without modifying the project
Description
A Maui app that references a class library can't be published without modifying the project file using the following command:
msbuild /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:TargetFrameworks="net6.0-windows10.0.19041;net6.0" /p:configuration=release /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=true /p:PackageCertificateThumbprint="YOUR_CERT_THUMBPRINT_HERE" /p:PackageCertificatePassword="AnyTestPasswordYouLike"
Steps to reproduce
- Create a Maui application.
- Create a class library.
- Reference the class library from the Maui application.
- Open a developer command prompt.
- Navigate to the Maui app folder.
- Run the command above to publish the app.
Workaround
- Update the project file with the following changes
- <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks> - <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks> + <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
- Update the command to use the following:
msbuild /restore /t:Publish /p:configuration=Release /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=true /p:PackageCertificateThumbprint="<<YOURTHUMBPRINTHERE>>" /p:PackageCertificatePassword="AnyTestPasswordYouLike"
I believe if you remove the following from the command line (without modifying the project file), this should work:
/p:TargetFrameworks="net6.0-windows10.0.19041;net6.0"
@dsplaisted unfortunately it doesn't because it also has the ios and android TFMs
I suppose there is a lot of same, or it's the same same problem, I have.
- Open Visual Studio 2022, version 17.3.0 Preview 3.0.
- Using VS, create a Maui project.
- Add a .NET 6 class library the the solution using VS.
- Reference this newly created .NET 6 class library in MauiProgram.
The class library project reference can be added to the Maui project. Using VS it is possible to navigate to it (<Ctrl+F12>). However when compiling an error is generated:
error CS0246: The type or namespace name 'TestClassLibrary' could not be found.
Here TestClassLibrary being whatever one used when generating the project.
The class library .csproj is as follows
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>
Different issues come if I add net6.0 to Maui program, change the library to netstandard2.1 or do something else.
@javiercn This issue does not repro when change the class library .csproj is <TargetFrameworks>net6.0;net6.0-windows</TargetFrameworks>, but there is a warning Path to mspdbcmf.exe could not be found.
And the https://github.com/aspnet/AspNetCore-ManualTests/pull/1519 has update the Blazor Hybrid Sample Project TFM.
So I want to confirm with you, should I need file a new bug to track this warning and close this issue?
 "C:\Users\v-xinyfe\source\repos\MauiApp1\MauiApp1\MauiApp1.csproj" (Publish target) (1:10) ->
(_EnsurePdbCmfExeFullPath target) ->
C:\Users\v-xinyfe.nuget\packages\microsoft.windowsappsdk\1.1.3\buildTransitive\Microsoft.Build.Msix.Packaging.target
s(341,5): warning : Path to
"C:\Users\v-xinyfe\source\repos\MauiApp1\MauiApp1\MauiApp1.csproj" (Publish target) (1:10) ->
(_EnsurePdbCmfExeFullPath target) ->
C:\Users\v-xinyfe.nuget\packages\microsoft.windowsappsdk\1.1.3\buildTransitive\Microsoft.Build.Msix.Packaging.target
s(341,5): warning : Path to mspdbcmf.exe could not be found. A symbols package will not be generated. Review https://
aka.ms/windowsappsdkdocs and ensure that all prerequisites for Windows App SDK development have been installed. [C:\Use
rs\v-xinyfe\source\repos\MauiApp1\MauiApp1\MauiApp1.csproj]
@EmilyFeng97 Just to be very clear, the issue is that you should be able to have a class library with just <TargetFramework>net6.0</TargetFramework>. What you are describing is at best a workaround.
I can't speak to the warning that you are seeing because that comes from the Windows SDK. If this is for manual testing purposes, I would stick to the workaround that I provided above.
I cross-reference https://github.com/dotnet/maui/issues/9091. I think this works for me now with the latest VS but there's similarish issue. That linked issue seem to be a show stopper if it is a supposed scenario, a bit similar to this and seem to be related around tooling with Maui and .NET 6.
@javiercn as mentioned in the Docs for this
Attempting to publish a .NET MAUI solution will result in the dotnet publish command attempting to publish each project in the solution individually, which can cause issues when you've added other project types to your solution. Therefore, the dotnet publish command should be scoped to your .NET MAUI app project.
Try specifically to specify the .NET MAUI csproj to publish. Additionally, you should be able to use dotnet publish now for the Windows target as well.
Let us know if that worked!
Hi @javiercn. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@jfversluis I was not publishing the solution. I was publishing the Maui project. I do not think that calling MSBuild vs MSBuild Core (dotnet publish) makes a difference here.
@javiercn the command you stated above does not reflect specifying the csproj. If you do not specify that explicitly it will try to publish the sln (or maybe each project in that folder individually, not really sure). You will have to specify the csproj in the command explicitly like so: msbuild MyApp.csproj /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=true /p:PackageCertificateThumbprint="YOUR_CERT_THUMBPRINT_HERE" /p:PackageCertificatePassword="AnyTestPasswordYouLike"
5. Navigate to the Maui app folder.
Are you saying that it will walk up the directory hierarchy and try to build the solution?
Let's put it this way: I have never seen it work if you don't specify the csproj explicitly :)
This might be a good test case and if it appears to be that, let's find out where to log a but to maybe change that before for the dotnet CLI tooling
@jfversluis I tried a few things and it does not make any difference.
- Using dotnet publishvsMSBuilddoes not fix the problem.
- Specifying the csproj file explicitly doesn't change the problem either.
The question then that I have is.
- Given a class library that targets .NET 6.0
- Given a Maui app created from the template that references that class library.
What command should a user run to produce a windows package that it can install in a machine
Hm that's strange then. In that case I need to dive into it again for a bit! Thanks for the investigation on your part!
@javiercn This issue also repro when publishing a Maui app that references a class library using the following command in Dev17.4 Preview 2 installed from PR412410. If I manually add "net6.0-android" to the SampleContent.csproj file and publish, this issue does not repro. Should I file a new bug to track this issue?
dotnet publish -f:net6.0-android -c:Release

installed from PR412410.
Does this still reproduce using the "normal" build of VS you utilize for validations.
installed from PR412410
We're still ironing out some details for that build, so it's not the best measure of whether or not a bug is still around 😄
@TanayParikh This issue repro on Dev17.4 Preview 2 installed from main branch when the MAUI project is created via CLI. And this issue does not repro if the MAUI project is created in VS. In windows testing scenarios, the MAUI project is usually created in VS. I created the project via CLI due to issue https://github.com/aspnet/AspNetCore-ManualTests/issues/1565. So should we ignore this issue?
So should we ignore this issue?
Thanks for the clarification. No we shouldn't ignore this issue if it repros on Dev17.4 Preview 2 installed from main branch. I just wanted to confirm it wasn't specific to the PR branch 😄
Thanks for the clarification. No we shouldn't ignore this issue if it repros on
Dev17.4 Preview 2 installed from main branch. I just wanted to confirm it wasn't specific to the PR branch 😄
This issue is not specific to the PR branch, it also repro on VS installed from main branch when the MAUI project is created via CLI. So should I file a new issue now about publishing projects created via the CLI, or file a new issue when the issue still repro after #8304 is fixed?
Thanks for the details @EmilyFeng97. Let's use this issue to track that as well. If after this issue is closed, projects created via CLI but published using VS are still failing, please create a new issue.
Any news about this issue? dotnet build -c Release -f net6.0-android failed when building a .NET MAUI containing several class libraries targeting net6.0 results in the same error.
@marcelbeeker which version of the SDK are you on (dotnet --version).
I believe @jinzhao1127 may have mentioned this no longer reproduces.
I believe @jinzhao1127 may have mentioned this no longer reproduces.
Yes, this issue does not repro anymore on both 6.0 and 7.0 Blazor Maui app that referenced razor class library app
The SDK version I use is version 6.0.402
I create a traditional Maui (XAML) app (not Blazor).
I referenced a Class library project targeting .NET6 (net6.0).
Finally I found out, the problem has something to do with the include of the Microsoft.NET.Test.Sdk in my Test project. When I remove this nuget I can build my projects without any problem.
I can't find out how I have to excute dotnet build -c Release -f net6.0-android (using in Azure Devops) for a solution a MAUI project which aslo contain a Xunit test project also.
Have next steps:
- Create default .NET MAUI project
- Create .NET 6 class library (with just one static string field to use in MAUI project)
- Add lib reference to .NET MAUI project
Publish (via wizard): For Debug|Any CPU is ok For Release|Any CPU (only difference in projects): Cannot resolve Assembly or Windows Metadata file '...\MauiAppTestPublish\ClassLibrary\bin\Release\net6.0\ClassLibrary.dll'
@Kazbek , Exactly that is my problem too. I cannot even add one .NET 6 project class library to my Maui Blazor app, and this exact same warning is presented to me. The build-solution even enters a state where it never completes.
I'm curious but isn't the whole point of .NET to self contain everything in the one sdk? Shouldn't it all just work without any extra fiddling around and additional dependencies?
I am facing the same problem as https://github.com/dotnet/maui/issues/8768 - considered as duplicate here, when publish in iOS. My MAUI Blazor project, with a Blazor class library: Can run in Debug mode, for both simulator and real device. For iOS, can build success in Release mode, but gets errors on publish. For Android, haven't tried yet. Im using lasted VS2022 Version 17.4.3, Xcode 14.2 (the problem happend before I update VS2022 to the lastest version, I can't remember the old version)
build command
dotnet publish -f:net7.0-ios -c:Release /p:ServerAddress=abc /p:ServerUser=abc /p:ServerPassword=abc /p:RuntimeIdentifier=ios-arm64 /p:TcpPort=58181 /p:ArchiveOnBuild=true /p:_DotNetRootRemoteDirectory=/Users/tranviettravel/Library/Caches/Xamarin/XMA/SDKs/dotnet/ 
error log
 Determining projects to restore...
  All projects are up-to-date for restore.
  Executing SayHello Task to establish a connection to a Remote Server.
                        Properties:
                                SessionId=79c3425643240xxxdeff14f87a3cf3c1443c1f155c3b556852dad0bbc62e6368,
                                Addresss=abc,
                                SshPort=22,
                                TcpPort=,
                                User=abc,
                                AppName=emTransViet,
                                VisualStudioProcessId=,
                                ContinueOnDisconnected=true
C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.1.1481\tools\msbuild\iOS\Xamarin.Shared.targets(1738,3): error : Could not find Microsoft.iOS in /Users/tranviettravel/Library/Caches/Xamarin/XMA/SDKs/dotnet/packs/Microsoft.iOS.Sdk/16.1.1481/. [C:\EventManage\
emTransViet\emTransViet.csproj::TargetFramework=net7.0-ios]
C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.1.1481\tools\msbuild\iOS\Xamarin.Shared.targets(1738,3): error :          [C:\EventManage\emTransViet\emTransViet.csproj::TargetFramework=net7.0-ios]
on MAUI Blazor app .csproj
 <PropertyGroup>
    <TargetFrameworks>;net7.0-ios;net7.0-android</TargetFrameworks>
..............
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
  <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
on the class library .csproj, I tried to add ;net7.0-ios;net7.0-android, but do not work, it has only 1 TargetFramework net7.0 as default.
  <PropertyGroup>
    <TargetFrameworks>net7.0;net7.0-ios;net7.0-android</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
The sdk folder above /Users/tranviettravel/Library/Caches/Xamarin/XMA/SDKs/dotnet/packs/Microsoft.iOS.Sdk/16.1.1481/  exists in my Mac, with contents inside.
