VSTS build ended with empty build artifacts - asp.net

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.

Related

dotnet publish command is not creating zip file for C# library

In visual studio solution I have single .net core 2.0 library project. And to the publish the library i am using dotnet publish -c release command
however its not zipping the publish folder. I have read the issue 6598 and use the suggested approach using dotnet build command as below
dotnet build ApiRouting.sln /nologo /p:PublishProfile=Release /p:PackageLocation="C:\temp\Routing\package" /p:OutDir="C:\temp\Routing\out" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform="Any CPU" /p:configuration="Release" /p:DesktopBuildPackageLocation="C:\temp\Routing\package\package.zip"
`
but that did not work either.
My project is aws lambda project which is C# library project not asp.net web project so i tried removing /p:WebPublishMethod=Package option but that did not work either.
Questions
1>What parameters i need to pass to publish command so that it would create zip file of publish folder.
2>In linked issue 6598 why its suggested to use build command instead of publish when build command only builds the project?
(on side note i can use aws tools for visual studio and use Publish to AWS Lambda and it creates zip file and deploys it to AWS directly from visual studio. However, we are using Jenkins for CI so i want use dotnet cli to create zip file so jenkins can execute that command and create zip file.)
i found it. These 2 links helped me
https://docs.aws.amazon.com/lambda/latest/dg/lambda-dotnet-how-to-create-deployment-package.html
https://docs.aws.amazon.com/lambda/latest/dg/lambda-dotnet-coreclr-deployment-package.html
first installed Amazon.Lambda.Tools
dotnet tool install -g Amazon.Lambda.Tools
and then to package and deploy
dotnet lambda deploy-function apirouting –-function-role myrole --profile lambdadep --profile-location C:\test\testawsprofile

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.

MSBuild doesn't create a Web Deploy Package from command line with VS2017 PublishProfile

I use Visual Studio 2017 and have created some publish profiles. One of these is a CustomProfile1 Web Deploy Package, it works like charm when pressing Publish and i get:
- BuildTest.deploy.cmd
- BuildTest.deploy-readme.txt
- BuildTest.SetParameters.xml
- BuildTest.SourceManifest.xml
- BuildTest.zip
I have tried numerous experiments with msbuild but does not work to generate the files from command line
msbuild Buildtest.sln /p:DeployOnBuild=true /p:PublishProfile=CustomProfile1.pubxml
bin and obj folders are getting filled, but apprently CustomProfile1 is not triggered from command line shot?
msbuild -version
Microsoft (R) Build Engine version 4.6.1586.0
[Microsoft .NET Framework, version 4.0.30319.42000]
The command is probably confused as to which configuration you want to build,try adding
/p:configuration=Debug
you can also put Staging or Release depending on which configuration you want.

Unable to publish ASP.NET web site using command line

I have a VS 2012 solution(ASP.NET) that contains three projects. I'm trying to deploy/publish the site via MsBuild command line without installing Visual Studio on our build machine.
I am using:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild Myproject.csproj /p:DeployOnBuild=true /p:PublishProfile= pubfile.pubxml /p:Password=user1 /p:AllowUntrustedCertificate=true
MY Command line output show only "build successfully" of the solution but nothing about the publish profile.
The same solution and batch file run successfully on my local machine.
Please suggest If any option for publishing without install VS on build Machine
I had to add the following to my command line
/p:VisualStudioVersion=11.0
or you might have to install Web Deploy on your build machine.
The other thing I had to do was publish from VS and save a publish profile and then used that on the command line. I see you have pubfile.xml, but all I had to do was reference the profile name, not the file name. QA being my profile name from the project. Try removing the .xml on the end of yours.
/p:PublishProfile=QA
Add C:\Windows\Microsoft.NET\Framework\v4.0.30319\ to your %PATH% system environment variable and invoke your command:
msbuild Myproject.csproj /p:DeployOnBuild=true /p:PublishProfile= pubfile.pubxml /p:Password=user1 /p:AllowUntrustedCertificate=true

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