Unable to publish ASP.NET web site using command line - asp.net

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

Related

Nothing to do. None of the projects specified contain packages to restore dotnet restore

I am working on an ASP.NET Web API 2 project with .NET target framework 4.6.1. I am trying to setup github workflow for my repo. When the dotnet restore command is run, it throws an error like below.
I am getting the same error if I run the same command in from command prompt inside my project. Also if I run dotnet build, it shows below error.
The project builds fine from Visual Studio but not working from command line or github workflow yml. Can anyone please point me on what am I missing?
The project builds fine from Visual Studio but not working from command line
Check which sln file Visual Studio is using to build your project.
Since I don't see any sln/csproj in your GitHub repository, it is also possible that you have a .gitignore which would prevent adding those in the first place.
DOTNET Restore does not support pacakges.config https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore
So you have to move the nuget package references to csproj file itself
Here is a great comment on how to do that https://stackoverflow.com/a/65701746/8318698
Note: check that if multiple projectGuid is there on csproj at the end of the steps
After that you will be able to use dotnet restore without a hitch.

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 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.

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.

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