question

Peterjc-4736 avatar image
0 Votes"
Peterjc-4736 asked TianyuSun-MSFT commented

How to build a .wapproj bundle using msbuild (command line)


I have a .wapproj project to bundle my WinUI3 application, and need to know how I can build this from the command line on our Build machine (running TeamCity)

I have install the build tools into C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools, and have tried running the following...

 "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\msbuild" "TestAppWinUI (Package).wapproj" /p:UapAppxPackageBuildMode=SideLoadOnly /p:AppxBundle=Never /p:AppxPackageOutput=d:\\0\\MsixDesktopApp.msix /p:AppxPackageSigningEnabled=false

However, I get the following errors

 Build started 14-Jun-22 11:05:23 AM.
 Project "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj" on node 1 (default targets).
 D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj(36,3): error MSB4019: The imported project "C:\Program Files (x86)\Microsoft
  Visual Studio\2022\BuildTools\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Micr
 osoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\DesktopBridge\\Microsoft.DesktopBridge.props" is correct, and that the file exists on disk.
 Done Building Project "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj" (default targets) -- FAILED.
    
    
 Build FAILED.
    
 "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj" (default target) (1) ->
   D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj(36,3): error MSB4019: The imported project "C:\Program Files (x86)\Microso
 ft Visual Studio\2022\BuildTools\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Mi
 crosoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\DesktopBridge\\Microsoft.DesktopBridge.props" is correct, and that the file exists on disk.
    
     0 Warning(s)
     1 Error(s)
    
 Time Elapsed 00:00:00.01

Would anyone know what I am doing wrong here?

Thanks in advance

[UPDATE1]

I tried using the path the Visual Studio msbuild rather than the build tools, ie "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild" with all the same above following it.

I now get a different error...

 Build started 14-Jun-22 2:40:51 PM.
 Project "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wap
 proj" on node 1 (default targets).
 _ResolveVCLibDependencies:
   Searching for SDKs targeting "UAP, 10.0.19041.0".
 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.target
 s(330,5): error MSB4036: The "GetFrameworkSdkPackages" task was not found. Check the following: 1.) The name of the tas
 k in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Micr
 osoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in t
 he *.tasks files located in the "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin" director
 y. [D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj]
 Done Building Project "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI
  (Package).wapproj" (default targets) -- FAILED.
    
    
 Build FAILED.
    
 "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj" (d
 efault target) (1) ->
 (_ResolveVCLibDependencies target) ->
   C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targ
 ets(330,5): error MSB4036: The "GetFrameworkSdkPackages" task was not found. Check the following: 1.) The name of the t
 ask in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Mi
 crosoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in
  the *.tasks files located in the "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin" direct
 ory. [D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wappro
 j]
    
     0 Warning(s)
     1 Error(s)

[UPDATE2]

Now after adding some more components to the build tools, I get a lot further, but still have an error related the the shared libs I also have (these are .net standatd 2.1)..

  D:\dev\MyApps\MyApp\MyApp.sln" (default target) (1) ->
     "D:\dev\MyApps\MyApp\MyAppWinUI\MyAppWinUI (Package)\MyAppWinUI (Package).wapproj" (d
     efault target) (7) ->
     "D:\dev\MyApps\MyApp\MyAppWinUI\MyAppWinUI\MyAppWinUI.csproj" (_GenerateAdditionalFra
     meworkSDKReference;_GetRecursiveResolvedSDKReferences;DesktopBridgeFrameworkSDKRegistrationOutputGroup target) (8:8) ->
     "D:\dev\MyApps\MyApp\shared\Common\MyCompany.MyApp.Common.csproj" (_GenerateAdditionalFrameworkSDKRe
     ference;_GetRecursiveResolvedSDKReferences;DesktopBridgeFrameworkSDKRegistrationOutputGroup target) (4:38) ->
     (ResolvePackageAssets target) ->
       C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,
     5): error NETSDK1047: Assets file 'D:\dev\MyApps\MyApp\shared\Common\obj\project.assets.json' doesn't have a
     target for 'netstandard2.1/win10-x64'. Ensure that restore has run and that you have included 'netstandard2.1' in the T
     argetFrameworks for your project. You may also need to include 'win10-x64' in your project's RuntimeIdentifiers. [D:\de
     v\MyApps\MyApp\shared\Common\MyCompany.MyApp.Common.csproj]

Each of these shared libs do referecne .NET standard 2.1 as the target framework...

211504-image.png

And it build fine from the IDE

I have the following installed for the build tools..

211389-image.png

211484-image.png

The contents of the shared\Common\obj\project.assets.json are

 {
   "version": 3,
   "targets": {
     ".NETStandard,Version=v2.1": {
       "Serilog/2.11.0": {
         "type": "package",
         "compile": {
           "lib/netstandard2.1/Serilog.dll": {}
         },
         "runtime": {
           "lib/netstandard2.1/Serilog.dll": {}
         }
       },
       "Serilog.Sinks.File/5.0.0": {
         "type": "package",
         "dependencies": {
           "Serilog": "2.10.0"
         },
         "compile": {
           "lib/netstandard2.1/Serilog.Sinks.File.dll": {}
         },
         "runtime": {
           "lib/netstandard2.1/Serilog.Sinks.File.dll": {}
         }
       }
     }
   },
   "libraries": {
     "Serilog/2.11.0": {
       "sha512": "ysv+hBzTul6Dp+Hvm10FlhJO3yMQcFKSAleus+LpiIzvNstpeV4Z7gGuIZ1OPNfIMulSHOjmLuGAEDKzpnV8ZQ==",
       "type": "package",
       "path": "serilog/2.11.0",
       "files": [
         ".nupkg.metadata",
         ".signature.p7s",
         "icon.png",
         "lib/net45/Serilog.dll",
         "lib/net45/Serilog.xml",
         "lib/net46/Serilog.dll",
         "lib/net46/Serilog.xml",
         "lib/net5.0/Serilog.dll",
         "lib/net5.0/Serilog.xml",
         "lib/netstandard1.0/Serilog.dll",
         "lib/netstandard1.0/Serilog.xml",
         "lib/netstandard1.3/Serilog.dll",
         "lib/netstandard1.3/Serilog.xml",
         "lib/netstandard2.0/Serilog.dll",
         "lib/netstandard2.0/Serilog.xml",
         "lib/netstandard2.1/Serilog.dll",
         "lib/netstandard2.1/Serilog.xml",
         "serilog.2.11.0.nupkg.sha512",
         "serilog.nuspec"
       ]
     },
     "Serilog.Sinks.File/5.0.0": {
       "sha512": "uwV5hdhWPwUH1szhO8PJpFiahqXmzPzJT/sOijH/kFgUx+cyoDTMM8MHD0adw9+Iem6itoibbUXHYslzXsLEAg==",
       "type": "package",
       "path": "serilog.sinks.file/5.0.0",
       "files": [
         ".nupkg.metadata",
         ".signature.p7s",
         "images/icon.png",
         "lib/net45/Serilog.Sinks.File.dll",
         "lib/net45/Serilog.Sinks.File.pdb",
         "lib/net45/Serilog.Sinks.File.xml",
         "lib/net5.0/Serilog.Sinks.File.dll",
         "lib/net5.0/Serilog.Sinks.File.pdb",
         "lib/net5.0/Serilog.Sinks.File.xml",
         "lib/netstandard1.3/Serilog.Sinks.File.dll",
         "lib/netstandard1.3/Serilog.Sinks.File.pdb",
         "lib/netstandard1.3/Serilog.Sinks.File.xml",
         "lib/netstandard2.0/Serilog.Sinks.File.dll",
         "lib/netstandard2.0/Serilog.Sinks.File.pdb",
         "lib/netstandard2.0/Serilog.Sinks.File.xml",
         "lib/netstandard2.1/Serilog.Sinks.File.dll",
         "lib/netstandard2.1/Serilog.Sinks.File.pdb",
         "lib/netstandard2.1/Serilog.Sinks.File.xml",
         "serilog.sinks.file.5.0.0.nupkg.sha512",
         "serilog.sinks.file.nuspec"
       ]
     }
   },
   "projectFileDependencyGroups": {
     ".NETStandard,Version=v2.1": [
       "Serilog >= 2.11.0",
       "Serilog.Sinks.File >= 5.0.0"
     ]
   },
   "packageFolders": {
     "C:\\Users\\peter\\.nuget\\packages\\": {},
     "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {},
     "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
   },
   "project": {
     "version": "1.0.0",
     "restore": {
       "projectUniqueName": "D:\\dev\\myApps\\myApp\\shared\\Common\\MyApp.Common.csproj",
       "projectName": "MyApp.Common",
       "projectPath": "D:\\dev\\myApps\\myApp\\shared\\Common\\MyApp.Common.csproj",
       "packagesPath": "C:\\Users\\peter\\.nuget\\packages\\",
       "outputPath": "D:\\dev\\myApps\\myApp\\shared\\Common\\obj\\",
       "projectStyle": "PackageReference",
       "fallbackFolders": [
         "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
         "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
       ],
       "configFilePaths": [
         "C:\\Users\\peter\\AppData\\Roaming\\NuGet\\NuGet.Config",
         "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
         "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
       ],
       "originalTargetFrameworks": [
         "netstandard2.1"
       ],
       "sources": {
         "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
         "https://api.nuget.org/v3/index.json": {},
         "https://nuget.devexpress.com/l7mX8Ehm2fdel1XJAtM3IPPgdx4Zxp3OOAjVmUEXfZxhQCQNQn/api": {}
       },
       "frameworks": {
         "netstandard2.1": {
           "targetAlias": "netstandard2.1",
           "projectReferences": {}
         }
       },
       "warningProperties": {
         "warnAsError": [
           "NU1605"
         ]
       }
     },
     "frameworks": {
       "netstandard2.1": {
         "targetAlias": "netstandard2.1",
         "dependencies": {
           "Serilog": {
             "target": "Package",
             "version": "[2.11.0, )"
           },
           "Serilog.Sinks.File": {
             "target": "Package",
             "version": "[5.0.0, )"
           }
         },
         "imports": [
           "net461",
           "net462",
           "net47",
           "net471",
           "net472",
           "net48"
         ],
         "assetTargetFallback": true,
         "warn": true,
         "frameworkReferences": {
           "NETStandard.Library": {
             "privateAssets": "all"
           }
         },
         "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.300\\RuntimeIdentifierGraph.json"
       }
     }
   }
 }



vs-msbuild
image.png (9.2 KiB)
image.png (95.5 KiB)
image.png (15.3 KiB)
· 11
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Try adding /p:VisualStudioVersion=20.0?

0 Votes 0 ·

Thanks for that @JunjieZhu-MSFT. I tired it, but unfortunately still the same error

0 Votes 0 ·

I added some more info in the question

0 Votes 0 ·

Hi @Peterjc-4736 , welcome to Microsoft Q&A forum. For Build Tools, could you confirm that the file C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.props mentioned in error message exists? For VS 2022 Enterprise MSBuild tool, could you confirm that the newly created WinUI3 project can be built well? Besides, did you change anything in proj file? If you can reproduce this issue on a newly created WinUI3 project, could you share me the steps to reproduce it on my side for further check?

0 Votes 0 ·

Hi @TianyuSun-MSFT,

I have since gone into the build tools installer, and added a new components, including the .NET desktop build tools, and Universal Windows Platform build tools, and a few individual components (perhaps did not need), and I now get a lot further. The file you mention does exist (well it does now)

What I have is a WinUI3 project, a WPF project, the .wapproj, and 3 library projects that target .NET standard 2.1... eg each one has the following...

The shared class libraries are referenced form the WinUI3, and the WPF project (WPF is just another experiment, and I am not packaging)

I tried using the .sln file rather than the .wapproj in the command line, eg

"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\msbuild" "Myapp.sln"

So now, I get the following (once for each shared lib file).. (see update2 in the post)



211511-image.png


[1]: /answers/storage/attachments/211483-image.png

0 Votes 0 ·
image.png (15.6 KiB)
image.png (9.2 KiB)

Hmm, ok maybe forget all the above.

I did a deploy from the IDE (to double check), then did a project clean, and it IS building from the command line...

0 Votes 0 ·

Ok, so everything works now? Looks like this issue is caused by the project cache.

0 Votes 0 ·
Show more comments

1 Answer

Peterjc-4736 avatar image
0 Votes"
Peterjc-4736 answered Peterjc-4736 published

I tried using the path the Visual Studio msbuild rather than the build tools, ie "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild" with all the same above following it.

I now get a different error...

 Build started 14-Jun-22 2:40:51 PM.
 Project "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wap
 proj" on node 1 (default targets).
 _ResolveVCLibDependencies:
   Searching for SDKs targeting "UAP, 10.0.19041.0".
 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.target
 s(330,5): error MSB4036: The "GetFrameworkSdkPackages" task was not found. Check the following: 1.) The name of the tas
 k in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Micr
 osoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in t
 he *.tasks files located in the "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin" director
 y. [D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj]
 Done Building Project "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI
  (Package).wapproj" (default targets) -- FAILED.
    
    
 Build FAILED.
    
 "D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wapproj" (d
 efault target) (1) ->
 (_ResolveVCLibDependencies target) ->
   C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targ
 ets(330,5): error MSB4036: The "GetFrameworkSdkPackages" task was not found. Check the following: 1.) The name of the t
 ask in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Mi
 crosoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in
  the *.tasks files located in the "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin" direct
 ory. [D:\dev\TestApps\TestApp\TestAppWinUI\TestAppWinUI (Package)\TestAppWinUI (Package).wappro
 j]
    
     0 Warning(s)
     1 Error(s)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.