VSTS Build failing - Error : Web deployment task failed - asp.net

I have a build definition in Visual Studio Team Services (previously Visual Studio Online) to build an ASP.NET web application using an on-premise agent. The agent has VS2012 installed and all the other necessary prerequisites to assist in building the application. However, when running the build, it fails and outputs below error:
C:\Program Files
x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4021,2):
Error : Web deployment task failed. (The .zip file package
'C:\BuildAgent\_work\1\a\' must be a file, not a directory.)
Process 'msbuild.exe' exited with code '1'.
I tried building the project on the agent machine using VS2012 and it builds fine. Also, I have defined following MSBuild parameters in the build definition which is same as my other builds that use a hosted agent:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
What could be the cause of this issue? Do I need to install anything extra?

You are using VS2012, you need to specify detail PackageLocation argument with .zip suffix ($(build.artifactstagingdirectory)\testWeb.zip). If you are using higher version of VS/MSBuild (e.g. vs 2015), a folder path is ok, it will adds [XXX].zip to the end of that path.

Related

Assets file project.assets.json doesn't have a target for 'net6.0-windows10.0.19041.0/win-x64'

I have a .NET 6 Windows Desktop app that I deploy with MSIX.
I can run and debug it on my own computer, but it fails to build with Azure Pipelines YAML.
I get the error:
C:\Program
Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5):
error NETSDK1047: Assets file 'D:\a\1\s\MyApp\obj\project.assets.json'
doesn't have a target for 'net6.0-windows10.0.19041.0/win-x64'. Ensure
that restore has run and that you have included
'net6.0-windows10.0.19041.0' in the TargetFrameworks for your project.
You may also need to include 'win-x64' in your project's
RuntimeIdentifiers.
App project file:
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<Platforms>x64</Platforms>
Installer project file:
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
The pipeline task is VSBuild with Visual Studio 2022 (v. 17)
Nuget tool is version 6.0 installed with NugetToolInstaller task.
Azure Windows agent uses vmImage: 'windows-2022'
The error says:
Ensure that you have included 'net6.0-windows10.0.19041.0' in the
TargetFrameworks for your project. You may also need to include
'win-x64' in your project's RuntimeIdentifiers.
I have added 'net6.0-windows10.0.19041.0' in the TargetFramework for both the app and the installer projects.
If I replace win10-x64 with win-x64 it can build, but I need to use win10-x64 because one of the packages requires it (Microsoft.PowerShell.SDK with System.Management.Automation).
NEW:
After adding /p:RestoreLockedMode=true in the VS Build task, I now get the error:
MyApp.Installer.wapproj : error NU1004: The project MyApp has no
compatible target framework. The packages lock file is inconsistent
with the project dependencies so restore can't be run in locked mode.
Disable the RestoreLockedMode MSBuild property or pass an explicit
--force-evaluate option to run restore to update the lock file.
NEW NEW: I upgraded to .NET 7 but get the same error.
How do I fix the error?

dotnet build stopped working after VS 2022 upgrade

I upgraded Visual Studio Community to the final release, and it stopped working. Specifically, I could generate a new project, but when I try to load it, it gave me an error
Critical Project 'SdkTest' load failed| [MSB4236] The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. ...\SdkTest.csproj
Even though build and run worked fine
I ran "repair" on VS2022, and it seems to be working now from Visual Studio. However, dotnet --info doesn't show any SDKs; only runtime; and dotnet build or dotnet new give an error:
C:\Code>dotnet new console -o myapp
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application 'new' does not exist.
* You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
I even reinstalled .NET 6 and I see it in the list of applications (along with older SDKs). I checked the path, and I see everything that I expect to see:
C:\Program Files (x86)\dotnet\
C:\Program Files\dotnet\
C:\Users\me\.dotnet\tools
I am running Windows 11.
It's known bug in VS2022 installation.
Problem is that dotnet you access is located inside Program Files(x86)/dotnet, but all sdk's are located in Program Files/dotnet. You simply need to edit PATH environment variable so Program Files/dotnet goes before Program Files(x86)/dotnet. If you don't see Program Files(x86)/dotnet in user environment variable (which is likely to happen) then edit system environment variable (located below)
Example with screenshots: https://stackoverflow.com/a/44272417/10339675

VSTS msdeploy.exe error: ERROR_USER_NOT_AUTHORIZED_FOR_CONTENTPATH

I'm trying to create a release definition inside VSTS to deploy my ASP.NET Core 2.0 app on my production server.
I'm using the MSDeployAllTheThings extension: https://marketplace.visualstudio.com/items?itemName=rschiefer.MSDeployAllTheThings
I'm able to deploy inside Visual Studio using the same configuration...
VSTS Config (not working)
VSTS Error
Visual Studio Config (working)
Do you guys have any ideas how to do that?
I had the same problem with deployment to smarterasp.net and was able to setup things for Web Deploy:
Your Dotnet Build task could create deployment package with necessary files like [YourProject].deploy.cmd, [YourProject].zip and etc. For this you could use next Arguments in your Build Task:
--configuration $(BuildConfiguration) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
Add "Batch script" task and set path to your [YourProject].deploy.cmd in Path field and also in your Arguments:
/y /m:$(SmarterAspNet.PublishUrl) -AllowUntrusted /u:$(SmarterAspNet.UserName) /p:$(SmarterAspNet.Password) /a:Basic "-setParam:name='IIS Web Application Name',value='$(SmarterAspNet.SiteName)'" -enableRule:AppOffline
With this two main DevOps tasks I was able to deploy my app to smarterasp.net
About MSDeployAllTheThings task: I removed it because it is not needed for me anymore
Not familiar with smarterasp.net. But this should be an issue with that site.
If you run the same msdeploy command from your local machine manually, you will get the same error message. We didn't see this error when use the same command to deploy to some other host instead of smarterasp.net. And if you add "-verbose" in the command, you will get a more detailed information which indicates that the command failed to adding the virtual path:
When you deploy your project from VS, it use the manifest file and source folder directly rather than "package" method. So you'd either contact smarterasp.net for help or use the same deploy method as Visual Studio or some other deploy method like FTP.

Running Angular 4 + Core 2.0 on IIS failing to start up

I have an application written in ASP.Net Core 2.0 using the Visual Studio Angular 2 template that I can run successfully on my local IIS installation and local commandline but fails on Windows Server 2012 R2 Standard.
From my local command line I can run:
dotnet myApp.dll
And the application runs successfully until ASP.Net core 2.0. When I copy the deployed application to my 2012 server (where the Core 2.0 runtime as been installed), I cannot call the same dotnet command (both calls are from within the root deployment folder for the app myApp).
On my desktop, the result is a web site that is listening at 5000 (ASP.Net core 2's default port I'm assuming) when running from the published site locations.
However, when I run this same command on the server, I get the error:
Unhandled Exception: System.AggregateException: One or more errors occurred. (We
bpack dev middleware failed because of an error while loading 'aspnet-webpack'.
Error was: Error: Cannot find module 'aspnet-webpack'....
....
....
) ---> Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException:
Webpack dev middleware failed because of an error while loading 'aspnet-webpack'
. Error was: Error: Cannot find module 'aspnet-webpack'
When I look up aspnet-webpack from npmjs.com, I note that this module is "This NPM package is an internal implementation detail of the Microsoft.AspNetCore.SpaServices NuGet package" according to NPM.
I'm assuming that somehow my Core 2.0 install in missing or not able to reference Microsoft.AspNetCore.SpaServices, but at this point I'm not sure where I should be looking for this.
Thanks for any input.
Look at your system variables (right click My PC > Properties > Environment Variables). ASPNETCORE_ENVIRONMENT has to be set to either Staging or Production if you do not have the dotnet sdk installed.
Once you change that value, change it in your project (Properties > Debug tab) as well. Redeploy your project and restart your server. You should see the site working now.
Good luck!

Self-contained deployment .NET Core app in Ubuntu

I wrote a test project using .NET Core and assembled the self-contained deployment for Ubuntu 16.04 as described here (see Self-contained deployment without third-party dependencies).
But when I run the app I get the following error:
An assembly specified in the application dependencies manifest (Test.deps.json) was not found:
package: 'runtime.linux-x64.Microsoft.NETCore.App', version: '2.0.0-preview2-25407-01'
path: 'runtimes/linux-x64/lib/netcoreapp2.0/Microsoft.CSharp.dll'
I am using .NET Core 2.0 Preview 2, VS2017 Preview.
I will be grateful for any help!
This is an old question, but I just ran across this when I was trying to run a .Net Core application on Linux and wanted to share the solution. If you are getting the error above, you are likely trying to execute the wrong binary. For those following along from scratch, follow these steps:
On Windows, open a command prompt in the directory of the project you want to run on Linux.
Build the project for Linux using dotnet publish -r linux-x64
I chose to target linux-x64, but you can target a specific runtime if you'd like. Runtime identifiers can be found here.
Copy the published files to the Linux workstation. Because the above command omitted the configuration flag -c, the configuration defaulted to debug. The published files will be in Debug\netcoreapp2.0\linux-x64\publish
Note: there will be binaries in Debug\netcoreapp2.0\linux-x64\ too. These are not the binaries you want to copy to your Linux workstation. If you run these binaries, you will get the error described in the OP. Copy all the files in the publish directory instead. Ignore whatever files might be in linux-x64.
On the Linux workstation, give execute permission to the binary file. My project was named ConsoleUI, so I used chmod 764 ConsoleUI
Execute the binary using ./ConsoleUI
Keep in mind that you will need to at least have the .Net Core runtime installed on your Linux workstation.

Resources