VSTS msdeploy.exe error: ERROR_USER_NOT_AUTHORIZED_FOR_CONTENTPATH - asp.net

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.

Related

VSTS build ended with empty build artifacts

We are using VSTS build using ASP.Net template. We are passing MSBuild Arguments as below-
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\"
We see no build error. From the log we observe a line -
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /LRM -p ..\LRM\ -u -f -d PrecompiledWeb\LRM\
where LRM is the .NET sln name which we are building. This sln contains multiple projects along with the LRM website.
At the end of the build pipeline we see no artifact generated. We see a warning at the "Publish Build Artifacts" saying -
2018-01-03T06:07:47.9208838Z ##[warning]Directory 'D:\VSTS Agents\DEV-QAS\A1\66\a' is empty. Nothing will be added to build artifact 'drop'.
Use below as msbuild arguments (/p:OutDir="$(build.stagingDirectory)" is the diffrence)
/p:TransformConfigFiles=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:OutDir="$(build.stagingDirectory)"
Use Publish task Path to publish as "$(build.stagingDirectory)\_PublishedWebsites" if you only want the website output. If all the files in staging directory required use "$(build.stagingDirectory)" as path to publish
I don't know the cause, but perhaps this alternative set of MSDeploy-targeted MSBuild parameters will prove to be a workaround.
/p:SkipInvalidConfigurations=true /p:DeployTarget=Package /p:PackageTempRootDir="$(Build.ArtifactStagingDirectory)"
It is the website, so you can’t publish it as the web application.
First, as ChamindaC said that you can specify OutDir argument, but it won’t generate the web deployment package, you can archive the folder to zip through Archive task. (Note: the value should be /p:OutDir="$(build.stagingDirectory)\\")
Secondly, it can generate the publishproj file once creating publish profile (right click website > Publish Web App). So you can specify that file in Visual Studio Build or MSBuild task with your MSBuild Arguments to publish website to web deployment package.
ASP.Net Web API MSBuild Arguments: /p:OutDir=$(Build.ArtifactStagingDirectory) /p:SkipInvalidConfigurations=true
Publish Build Artifacts :
Path to Publish: $(Build.ArtifactStagingDirectory)_PublishedWebsites
The above configuration is working for me, please check the image for details.

How do I git deploy an .fsproj based f# project to azure?

I have an ASP.NET core application that I've been auto-deploying to an azure app service on commit to a git repo. It worked fine as a project.json type project.
I've converted my project.json to myproject.fsproj and it builds and runs locally. On comitting the .fsproj to git, the deployment was triggered, but it failed with the activity log containing one line: 'D:\home\site\repository\myproject.fsproj' is not a deployable project.
I guess it's an issue with the default kudu deployment script? Does anyone know how to sort this out, or do I need to submit an issue/RFC to the kudu guys?
UPDATE
I generated the original .fsproj using:
dotnet new mvc --language f# --framework netcoreapp1.0
I've since made changes to it, so I will try to do a minimal case later tonight.
Turns out that the default deployment in azure wouldn't deal with this.
Following the answer on Kudu Deployment Script for ASP.NET Core 1.0, I generated a custom deployment script using:
npm install -g kuduscript
kuduscript -y --aspNetCore myproject.fsproj
Added the resulting deploy.cmd along with a .deployment:
[config]
command = deploy.cmd
A deployment triggered by a push to git works as expected now.

GIT based asp.net web app fails to deploy to Azure with typescript compile error

I have this asp.net (4.6.2) web application which compiles and runs fine on my local machine.
The project is in a Git repo in VSTS.
I want this site deployed to Azure web sites. So I make a Webapp and set the deployment option to my VSTS Git repo.
This will automatically trigger a deployment... which fails.. with this error:
All packages listed in packages.config are already installed.
D:\home\site\repository\FormBuilder\Scripts\typings\knockout\knockout.d.ts(335,13): error TS1110: Build: Type expected. [D:\home\site\repository\FormBuilder\FormBuilder.csproj]
D:\home\site\repository\FormBuilder\Scripts\typings\knockout\knockout.d.ts(338,11): error TS1109: Build: Expression expected. [D:\home\site\repository\FormBuilder\FormBuilder.csproj]
D:\home\site\repository\FormBuilder\Scripts\typings\knockout\knockout.d.ts(339,1): error TS1128: Build: Declaration or statement expected. [D:\home\site\repository\FormBuilder\FormBuilder.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\FormBuilder\FormBuilder.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d3e9219d2f6f3b";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository.\"
An error has occurred during web site deployment.
It looks to me like it's compiling my .d.ts files. Don't know why..VS2015 does not do that.
I tried to exclude this file in a tsconfig but that does not work.
How can I make this build succeed?
So the problem is that the Azure build machine is not equipped with typescript 2.0 (yet) and knockout.d.ts uses a 2.0 syntax for something. See the comments below the question.
GitHub issue here
You need to compile type script files before deploying to azure. In deploy.cmd file on azure you can add this code to Compile TypeScript right after the npm packages are installed.
echo Transpiling TypeScript in %DEPLOYMENT_TARGET%...call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -p "%DEPLOYMENT_TARGET%"
You can find the deploy.cmd file on KUDU in site->deployments->tools section.

VSTS Build failing - Error : Web deployment task failed

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.

Deploy from command line using MSBUILD and or MSDEPLOY (.NET 3.5)

I'm trying to get my website deployed by a Jenkins job.
I'm using the following command line sentence, with no success:
"C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe" myproj.csproj /p:DeployOnBuild=true
I've also tried:
"C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe" myproj.csproj /p:Configuration=Debug /p:OutputPath="obj\debug" /p:DeployIisAppPath="Default Web Site/demo"
None works although my project is compiled properly.
WHen I go to C:\inetpub\wwwroot nothing new is there. I want my site to start running and be accesible from my browser in Localhost.
You can use MSDeploy to deploy your web app using the following MSBuild arguments
/p:Configuration=release
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=https://targetServer:8172/MsDeploy.axd
/p:DeployIisAppPath=MySite
/p:AllowUntrustedCertificate=True
/p:Username=
/p:AuthType=NTLM
MSDeploy, however, has proven to be better solution for us. We use MSBuild to create an MSDeploy package and then we can deploy that package to many environments using MSDeploy.exe. Build once, deploy many. Here is an overview of WebDeploy which may be helpful:
http://dotnetcatch.com/2016/02/25/the-anatomy-of-a-webdeploy-package/
Make sure that you are adding the correct parameters after the MSBuild command, such as /p:DeployOnBuild=true /p:PublishProfile="XXXProfile", but the most important is to add the MSBuild.exe path to your %PATH% environment variable.
Having the MSBuild.exe path added to your %PATH% system environment variable the only thing you need to do is call:
msbuild myproject.csproj /p:DeployOnBuild=true /p:PublishProfile="MyProfile", where MyProfile is the generated publishing profile with Visual Studio and can be found under MyProject\Properties\PublishProfiles folder.

Resources