Core: Error attempting to create app package using Windows Application Package project type (desktop bridge)

Created on 2 Aug 2019  路  13Comments  路  Source: dotnet/core

Issue Title

A build error is returned attempting to build a Windows Application Package project.

Tool Versions

Visual Studio Enterprise 2019 Preview 16.3.0 Preview 1.0
.NET Core 3.0.100-preview7-012821

General

I'm not sure if this issue is with Visual Studio, MSBuild, or .NET Core, so I'm posting here.

I've recently been testing out creating a so-called "desktop bridge" project for a WPF app I'm writing. Everything seems to work except that I get a build error when I try and create an app package. The entire solution compiles just fine; it's only the app package creation that's failing:

1>------ Publish started: Project: WindowsApplicationPackage, Configuration: Debug x64 ------
1>Restore completed in 3.55 ms for C:\...\src\Sdk\Sdk.csproj.
1>Restore completed in 2.4 ms for C:\...\src\WpfApp\WpfApp.csproj.
1>Could not find project item with item type 'ProjectReference' and include value '..\Sdk\Sdk.csproj'.
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
========== Package: 0 succeeded, 1 failed ===========

The Sdk project is a .NET Core 3.0 class library that contains references to WPF's FrameworkElement, which itself requires that I reference the following two packages:

<PackageReference Include="Microsoft.NET.Sdk.WindowsDesktop" Version="3.0.0-preview3-27504-2" />
<PackageReference Include="Microsoft.WindowsDesktop.App" Version="3.0.0-preview7-27912-14" />

The WpfApp project is a .NET Core 3.0 Windows application that has a project reference to the Sdk project:

<ProjectReference Include="..\Sdk\Sdk.csproj" />

When I run WpfApp in Visual Studio, the app works perfectly.

I tried changing the two MSBuild output settings to Diagnostic but there was no meaningful output in addition to what I pasted above.

I've tried removing projects from the solution and re-adding them and re-adding project references but nothing has helped. Unfortunately, the solution contains proprietary code that I am not allowed to post publicly.

Any idea what's going on?

Most helpful comment

@nguerrera @mslukewest This issue is fixed in 16.3 Preview 2.

All 13 comments

FWIW, I was able to use a combination of makeappx.exe and signtool.exe to bypass this issue. That makes me think it's a problem with the Visual Studio tooling.

@livarcocc @nguerrera can you take a look in case this is an MSBuild problem?

Don't PackageReference these:

<PackageReference Include="Microsoft.NET.Sdk.WindowsDesktop" Version="3.0.0-preview3-27504-2" />
<PackageReference Include="Microsoft.WindowsDesktop.App" Version="3.0.0-preview7-27912-14" />

It's a bug that the first one is even on NuGet I think, and the second one should have given you an error. I will follow up on both.

You should have this instead for your WPF class library, as also seen via dotnet new wpflib or equivalent File -> New in VS:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>

I don't know that above is related to the issue. I will need to try and repro it.

I'm trying this proposal now. Will report back shortly.

I remember that I tried this before. It doesn't work. The compiler can't find FrameworkElement and I get a confusing warning, as well:

Error   CS0246  The type or namespace name 'FrameworkElement' could not be found (are you missing a using directive or an assembly reference?)  Sdk ...\src\Sdk\IUiModule.cs
Error   CS0246  The type or namespace name 'FrameworkElement' could not be found (are you missing a using directive or an assembly reference?)  Sdk ...\src\Sdk\UiModule.cs
Error   CS0246  The type or namespace name 'FrameworkElement' could not be found (are you missing a using directive or an assembly reference?)  Sdk ...\src\Sdk\UiModule.cs
Warning NETSDK1107  Microsoft.NET.Sdk.WindowsDesktop is required to build Windows desktop applications. 'UseWpf' and 'UseWindowsForms' are not supported by the current SDK.    Sdk C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets   340 

My project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWpf>true</UseWpf>
    <AssemblyName>Sdk</AssemblyName>
    <RootNamespace>Sdk</RootNamespace>
    <Authors>...</Authors>
    <Product>...</Product>
    <Nullable>enable</Nullable>
    <LangVersion>8.0</LangVersion>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Serilog" Version="2.8.0" />
  </ItemGroup>
</Project>

I'll also stress that the only way I've been able to get this to work in any fashion (using CLI tools as mentioned earlier) was to include those two <PackageReference> elements. Whether it's right or wrong, I can't say.

You need this additional change to the project file

- <Project Sdk="Microsoft.NET.Sdk">
+ <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

That warning NETSDK1107 is trying to alert you to that, but it could be worded better.

That appears to have worked! Thanks!

So really, this just comes down to the fact that VS 2019 doesn't yet have the correct project templates for what I'm trying to do.

Whoops; closed the issue too quickly.

Unfortunately my warning is still present even after verifying all my projects now use <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">:

1>Could not find project item with item type 'ProjectReference' and include value '..\Sdk\Sdk.csproj'.

Here's the Wpf project file:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWpf>true</UseWpf>
    <AssemblyName>...</AssemblyName>
    <RootNamespace>.../RootNamespace>
    <ApplicationIcon>app.ico</ApplicationIcon>
    <Authors>...</Authors>
    <Company>...</Company>
    <Product>...</Product>
    <Platforms>x64</Platforms>
    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
    <Nullable>enable</Nullable>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Autofac" Version="4.9.3" />
    <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.0.0-preview7-27912-14" />
    <PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
    <PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
    <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Sdk\Sdk.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Resource Include="app.ico" />
  </ItemGroup>
  <ItemGroup>
    <None Update="App.xaml">
      <Generator>MSBuild:Compile</Generator>
    </None>
    <None Update="MainWindow.xaml">
      <Generator>MSBuild:Compile</Generator>
    </None>
  </ItemGroup>
</Project>

@MSLukeWest can you look at this?

@nguerrera @mslukewest This issue is fixed in 16.3 Preview 2.

I just installed .NET Core 3.0 Preview 8 and VS 2019 Preview 16.3.0 Preview 2 and can confirm the issue is resolved. Thank you!

Was this page helpful?
0 / 5 - 0 ratings