How do I build a .NET WinUI 3 App without VisualStudio?

Geronimus 20 Reputation points
2023-05-31T20:50:51.39+00:00

Let's say that the VisualStudio license terms don't fit my use case. Perhaps my employer defines itself as a "Java shop", and I'd like to show them the goodness of native apps. But I can't do so by producing an app they're not free to distribute.

So I'm trying to build a WinUI 3 app with the dotnet CLI. I've tried to reproduce the essence of the build file for the SimplePhotos tutorial app.

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>MyOrg.MyApp</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x64;ARM64</Platforms>
    <RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <WindowsPackageType>None</WindowsPackageType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230313.1" />
    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
    <Manifest Include="$(ApplicationManifest)" />
  </ItemGroup>

</Project>

And I've created an app.manifest file:

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity version="1.0.0.0" name="MyApp.app" />

  <compatibility>
    <application>
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
    </application>
  </compatibility>
  
  <application>
    <windowsSettings>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
    </windowsSettings>
  </application>

</assembly>

For argument's sake, let's say I have minimal App.cs and MainWindow.cs files.

Now I try to build the app, and I see:

PS > dotnet build MyApp/MyApp.csproj

C:\Users\<my-user-id>\.nuget\packages\microsoft.windowsappsdk\1.2.230313.1
\buildTransitive\MrtCore.PriGen.targets(911,5): error MSB4062: The
"Microsoft.Build.Packaging.Pri.Tasks.ExpandPriContent" task could not be
loaded from the assembly C:\Program Files\dotnet\sdk\7.0.302\\Microsoft
\VisualStudio\v17.0\AppxPackage\\Microsoft.Build.Packaging.Pri.Tasks.dll.
Could not load file or assembly 'C:\Program Files\dotnet\sdk\7.0.302\Microsoft
\VisualStudio\v17.0\AppxPackage\Microsoft.Build.Packaging.Pri.Tasks.dll'.
The system cannot find the path specified. Confirm that the <UsingTask>
declaration is correct, that the assembly and all its dependencies are
available, and that the task contains a public class that implements
Microsoft.Build.Framework.ITask.

Build FAILED.

Is there any way to build this project without a VisualStudio installation?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,264 questions
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
711 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
316 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,098 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 24,276 Reputation points Microsoft Vendor
    2023-06-01T06:39:29.8733333+00:00

    @Geronimus, Welcome to Microsoft Q&A, based on the Microsoft Learning Other limitations and known issues, this is a known issue.

    Please set <EnableMsixTooling>true</EnableMsixTooling> in your project file.

    Based on my test, it works well, which could build the file successfully without any errors.

    User's image

    Hope my solution could be helpful for you.

    Best Regards,

    Jack

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.  

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful