How to build MAUI.NET solution with few projects into standalone exe file - c#

I have solution - MAUI.NET application that has references to other projects in this solution. I have created them all for .NET 6 and all of them were upgraded to .NET 7.
I need to ship this application as .exe file to the user. I found a nice command I am trying to execute in Developer Command Prompt for VS 2022:
msbuild /restore /t:build /p:TargetFramework=net7.0-windows10.0.19041 /p:configuration=release /p:WindowsAppSDKSelfContained=true /p:Platform="Any CPU" /p:WindowsPackageType=None /p:RuntimeIdentifier=win10-x64
also I proceed this with dotnet restore and msbuild /restore.
I also did addition of <WindowsPackageType>None</WindowsPackageType> into .csproj of the main project in solution and changed "commandName" in launchSettings.json into Project.
Visual Studio was updated yesterday - 17.4.5. NuGet package manage is 6.4.0 version.
The application runs in debug well.
Is it possible to build this for Windows as .exe that can be moved away (without the whole stuff in /bin)?
What else I miss to build this way?
I am getting an errors like follows:
C:\Program Files\dotnet\sdk\7.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\...\obj\project.assets.json' doesn't have a target for 'net7.0-windows10.0.19041.0'. Ensure that restore has run and that you have included 'net7.0-windows10.0.19041.0' in the TargetFrameworks for your project.
C:\Program Files\dotnet\sdk\7.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\...\obj\project.assets.json' doesn't have a target for 'net7.0'. Ensure that restore has run and that you have included 'net7.0' in the TargetFrameworks for your project.


Azure Pipeline deploy to Web App Service failing with Missing required property 'OutputPath'

I am running into an issue with deploying to Azure Web App resource I've got set up. I can't find much about this error online so posting here...
I have a .NET solution with a main project and several class library projects which i make references to in my main project.
For some reason, the deployment is failing because it doesn't pick up those dll projects in the solution. My code is on a bitbucket repo and I've set it to deploy to my web app resource whenever I make a commit to a certain branch.
But it is failing with this error:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin\amd64'.
All packages listed in packages.config are already installed.
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: D:\home\site\repository\XXXCode\XXXXX.Entities\XXXXX.Entities.csproj.
Failed exitCode=1, command=nuget restore "D:\home\site\repository\XXXCode\XXXCode.sln"
An error has occurred during web site deployment.
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: D:\home\site\repository\XXXCode\XXXXX.Entities\XXXXX.Entities.csproj.\r\nD:\Program Files (x86)\SiteExtensions\Kudu\82.10503.3890\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
Am i missing a step here?
I'm new to this so I probably forgot a step somewhere.
Any help greatly appreciated, thanks!
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program
Files (x86)\MSBuild\14.0\bin\amd64'.
According to this error message, apparently the version you are using is MSBuild 14.0(VS 2015 tools).
And also, from this message:
Missing required property 'OutputPath' for project type
As far as I understood, the PackageReference just works with MSBuild version 15 and higher, instead of 14.0. Since it came with VS 2017, and at the same time MSBuild 15.0.
So, for solve this error, I recommend you try with the newer version: MSbuild 15.0.
You can also refer to this ticket: Missing required property 'OutputPath' for project type 'PackageReference'
First, please ensure that your script can be executed successfully in VS2017 locally.
And then, if you build with Visual Studio build task, change the Visual Studio Version as:
Or, if its MSBuild task you are using, just need to change the MSBuild Version:
On the other hand, if you are using Specify Location instead of Version in MSbuild task, specify the location path of MSBuild.exe which under MSBuild 15.0. For me, I am using VS2019, so the location of MSbuild 16.0 is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe
Since you are using VS2017, you can specified the location of MSbuild 15.0 with your MSbuild 15.0 file path as:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64

Visual Studio auto restores dll packages

In the company I work, inside every solution we have one folder packages, which contains all dll dependencies. This folder is not in repository with the rest of the solution.
Every time I build one project, all files inside folder packages are restored and any missing dlls appear again. This happens in the beginning of the build, no matter if the build succeeds of fails. Even if the project has no dll dependencies, any missing dlls in packages are restored.
I suspect it is a setting in msbuild but I cannot find it. Does anyone know where it might be or if there is a place with msbuild *.targets files?
thanks for any help
This is because Visual Studio restores packages defined in the packages.config files.
You can control this behaviour in Visual Studio in options:
From the MS Docs regarding regarding Nuget:
MSBuild: use the msbuild -t:restore command, which restores packages
packages listed in the project file (PackageReference only). Available
only in NuGet 4.x+ and MSBuild 15.1+, which are included with Visual
Studio 2017. nuget restore and dotnet restore both use this command
for applicable projects.
Further down, there's quite a bit about enabling/disabling and modifying this behavior in a variety of ways.
Allow NuGet to download missing packages: controls all forms of
package restore by changing the packageRestore/enabled setting in the
NuGet.Config file as shown below (%AppData%\NuGet\NuGet.Config on
Windows, ~/.nuget/NuGet/NuGet.Config on Mac/Linux). In Visual Studio,
this setting allows the Restore NuGet Packages command on the
solution's context menu to work.
Appearing to be more to your issue:
Automatically check for missing packages during build in Visual
Studio: controls automatic restore by changing the
packageRestore/automatic setting in the NuGet.Config file as shown
below (%AppData%\NuGet\NuGet.Config on Windows,
~/.nuget/NuGet/NuGet.Config on Mac/Linux). When this option is set,
running a build from Visual Studio automatically restores any missing
packages. The option does not affect builds run from the command line
using MSBuild.

TFS 2015 "vNext" Build for web project in solution

I am trying to achieve setting up a vNext build definition on TFS 2015 (the project is actually a .NET 4.6.1 web project, but I want to use the new TFS build setup). I am struggling with finding documentation on only deploying a specific web project in my solution (2 web projects, 3 class libraries and subsequent tests).
In the XAML build approach, I would specify the .sln and the .csproj file relevant to the build in the Process > 2. Build > Projects input. The "Visual Studio Build" step does not allow for multiple project inputs in the same way, and this seems to be where I am getting stuck. If I only specify the .csproj, Nuget packages do not get restored and the build fails.
Is there any known documentation for deploying a C# web project (.csproj) ONLY via these vNext builds?
MSBuild arguments previously used in XAML Build:
/p:AllowUntrustedCertificate=True /p:AuthType=NTLM /p:Configuration=Development /p:DeployOnBuild=True /p:PublishProfile="DEV" /toolsversion:14.0 /p:VisualStudioVersion=14.0 /p:GenerateBuildInfoConfigFile=false
The solution I am searching for would accomplish the following:
Builds at the very least the Web.csproj with project dependencies
Restores Nuget packages
Transforms web configs
Deploys Web project to two separate servers (non-Azure!) via, ideally, web deploy
Thanks in advanced for any help. Hopefully this is possible!
Note: I am not on Azure and Azure is not an option. I know there are tons of documented use case scenarios for Azure users, which is great... but, yeah.
You can add a "NuGet Installer" task at the top of your build definition to restore the nuget packages for your solution and specify the .csproj in Visual Studio Build Step.
If you want to build the entire solution, you can add following arguments in "MSBuild Arguments":
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
This will create the deploy packages for your projects separately in "$(build.artifactstagingdirectory)\" folder like following:
Then you can choose the package for the project you want to deploy. And with the deploy package, you can add two "Command Line" tasks in your build definition and call "Project.deploy.cmd" under "$(build.artifactstagingdirectory)\" folder to deploy the project to your servers. Reference about deploy from command: Executing the Command File. Web.config will be transformed by default if you have configured it correctly.
By the way, I recommend you to deploy your projects by using the release management system instead of deploying them in build.

Nuget Restore via build server "unable to find version"

I have a VS solution and as part of a TeamCity Build, we restore packages from both a private NuGet feed (myget) and the public feed ( Most packages restore fine, but it hangs on the ones below for WebApi and Mono.Security. This is all working locally in Visual Studio.
[restore] NuGet command: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe restore C:\TeamCity\buildAgent\work\953bd084b49f7d88\DataFinch.Web.sln -Source<hidden>/api/v2 -Source
[11:41:35][restore] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script473789219385667038.cmd
[11:41:35][restore] in directory: C:\TeamCity\buildAgent\work\953bd084b49f7d88
[11:41:35][restore] JetBrains TeamCity NuGet Runner 8.0.37059.9
[11:41:35][restore] Registered additional extensions from paths: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\plugins-2.8
[11:41:35][restore] Starting NuGet.exe 2.8.50926.602 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Client'.
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Core'.
[11:41:43][restore] Unable to find version '' of package 'Mono.Security'.
[11:41:43][restore] Unable to find version '6.0.4' of package 'Newtonsoft.Json'.
[11:41:43][restore] Process exited with code 1
Teamcity config:
Try using of per the nuget docs:
The reason why the build failed, was an old version of nuget.exe. I finally solved this problem by downloading the latest version and put this executable in the Program Files x86 folder. Then I created a new system variabele to point to this executable. After that I add a NuGetInstaller package in my TFS Build Definition to let me configure TFS using this new NuGet.exe.
This link helped me to let TFS use this new NuGet version
I followed this:
I had tried 3.3 and got this error:
Restoring NuGet package Microsoft.AspNet.WebPages.3.2.3.
WARNING: Unable to find version '' of package 'Antlr'.
I downloaded the latest NuGet and set the Custom path to NuGet and that failed as well.
Surprisingly when I switched to 3.5 it worked.
If you are really stuck, run the command in a Command Line Prompt and it will work:
C:\Program Files (x86)\NuGet\nuget.exe restore -NonInteractive E:\agentXYZPool\_work\1\s\xyz.sln
I ran into this problem with one of our build slaves leveraging TFS and Visual Studio.
The way I fixed it was, I opened the solution that wasn't compiling in Visual Studio, right-clicked on the SLN and selected "Enable Restore NuGet Packages"
That prompts a dialog box that you have to accept. After you've done that, you might be good to go. Right-click on the SLN again and run "Restore NuGet Packages", and if that operation succeeds, you're golden.
There's probably some setting you can adjust programmatically when setting up your slave environments, but that's one direct way to fix this kind of problem.
According to THIS current document as of this writing from MS, the proper url is:
So I went about to fix the issue because I assumed it had nothing to do with the URL. I did 2 things, not sure which it was that resolved the issue but I'll post both here in case it helps someone.
Within TFS2018 and within my build step for the installation of Nuget I specified version 4.9.3 (the reason I chose 4.9.3 because I noticed by looking at detailed log of VS that during my build it was using this version) and chose to always download the latest version.
Second thing I did was I removed a Nuget.Config file from my project that was left over from something I was testing. Then I re-commited my changes to TFS
After I did both of the above steps the rest of my build started working.
Using an old version of Visual Studio's Nuget
Visual Studio has C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\Nuget.exe. Jenkins was using that to nuget restore
Updated Nuget in program files,
C:\Program Files (x86)\NuGet> ./nuget.exe update -self
Pointed Jenkins at that new Nuget path and 🔥cooking with gas🔥
SET PATH=%PATH%;C:\Program Files (x86)\NuGet
nuget restore SolutionName.sln

How do I get Nuget 2.x to run solution level package Init.ps1's?

I have a few solution level NuGet packages attached to a Visual Studio 2010 solution via .nuget/packages.config.
These packages each contain a Init.ps1 file. I'm trying to pre-install the packages via commandline or script on my CI server. Running nuget install .nuget\packages.config -o packages pulls the packages down into the packages folder. But it does not run the Init.ps1 scripts.
If I attempt and msbuild call on the solution file, it fails because required files installed by the package Init.ps1 files are not in place yet.
If I open up the solution in Visual Studio, the packages run Init.ps1.
How can I get the Init.ps1 files to fire along with the package install from a commandline/script without having to open Visual Studio?
The best you can do is fake it. Run the scripts by hand by invoking PowerShell. But there might be problems with them. The $project argument passed to init.ps1 is a DTE object, and you can't make it available without a full copy of VS.