MSbuild command line - Publish artifacts on specfic location - msbuild

Now I can able to build successfuly, artifacts created under obj/Debug/package/packageTmp/
can you please let me know how to publish into some other directory in same machine .
Command:
MSBuild.exe C:\RD\DigitalTechnology\Trunk\SQLDeployment\SQLDeployment.sln /p:VisualStudioVersion=14.0 /p:DeployOnBuild=true

For a .Net application you can use:
/p:OutDir=c:\My\BuildDropLocation\ProjectName
For a web project you have to use this statement:
/p:DeployOnBuild=true
/p:DeployDefaultTarget=WebPublish
/p:WebPublishMethod=FileSystem
/p:DeleteExistingFiles=true
/p:publishUrl=c:\My\BuildDropLocation\ProjectName

Related

MSBuild arguments to generate files

notes:
Visual Studio 2017 solution with an MVC web app and several other projects, not all of which are referenced by the web app project. Until now Ive been using VS directly to publish to a test server, but I have moved things into VSTS and have a build & release definition setup but not working yet.
What im trying to achieve, is to get my (hosted) VSTS build agent to produce the published files that my (on-prem) release agent can simply copy to its target destination. So, Im trying to test the MS build step locally from the VS command line so as to get the files produced and note the path they are at. Maybe Im making this more complicated that it needs to be?
These options will create a single zipped archive and its associated files and place it into the artefact staging dir. Is there a way to simply publish the files WITHOUT putting them in an archive - and directly into the artefact staging dir?
Visual Studio Build
MSBuild parameters
/t:My_MVCWeb_Project_Name /p:DeployOnBuild=true
/p:WebPublishMethod=FileSystem /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\\"
In my release using on-prem agent),
I have a "copy files" task, with the destination as the unc path where the IIS app is located. However, that will just copy over the archive. So how can I just copy the files as if I was using a publish profile, straight to the app directory?
[update2 - still getting zip file produced ]
MSBuild my_solution_name /t:"my_project_name" /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:PackageLocation="D:\temp\local-dev-build-dir"
[ update 3 ]
Trying these from the command line as a test, but nothing is generated
msbuild D:\app_dir>MSBuild my_solution_name.sln /t:"my_web_proj_name" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="D:\temp\app_build_dir\\"
/p:DeployDefaultTarget=WebPublish
Using these MSBuild Arguments instead:
/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish
Remove the
/p:PackageAsSingleFile=true
Or change it to:
/p:PackageAsSingleFile=false
That is causing the files to be zipped up.
You may also need to switch the publishing method to package:
/p:OutDir=$(build.artifactstagingdirectory)
/p:WebPublishMethod=Package

dotnet publish command is not creating zip file package for asp.net core web application project

I am trying to create a web deployment package for asp.net core web application. When I tried to publish the output as a package using VS2017, I got all the necessary files in "Publish" folder as well a zip file containing all those files in given location.
However I want to have the same using command line. I am able to get "Publish" folder, but not a zip file. What am I doing wrong? Can someone correct my command?
dotnet publish /p:target=package /p:WebPublishMethod=Package /p:LastUsedBuildConfiguration=Release /p:LastUsedPlatform="Any CPU" /p:LaunchSiteAfterPublish=True /p:ExcludeApp_Data=False /p:PublishFramework=netcoreapp1.0 /p:UsePowerShell=True /p:DesktopBuildPackageLocation=C:\Kannan\Temp\package.zip /p:PackageLocation="C:\kannan\temp\package.zip" /p:PackageFileName=C:\kannan\temp\package.zip /p:PackageAsSingleFile=true
What am I doing wrong? Can someone correct my command?
It`s depends on the version of your cli.
If you are using the 2.0 version of cli, then you can use dotnet publish command on a windows machine and it would work.
dotnet build WebApplicationDeploy.sln /nologo /p:PublishProfile=Release /p:PackageLocation="C:\Some\Path\package" /p:OutDir="C:\Some\Path\out" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform="Any CPU" /p:configuration="Release" /p:DesktopBuildPackageLocation="C:\Some\Path\package\package.zip"
But if you are using 1.0.4 version of the cli, then you should use the msbuild version of the command (The ability to call dotnet build was added in 2.0 cli).
msbuild WebApplicationDeploy.sln /nologo /p:PublishProfile=Release /p:PackageLocation="C:\Some\Path\package" /p:OutDir="C:\Some\Path\out" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform="Any CPU" /p:configuration="Release" /p:DesktopBuildPackageLocation="C:\Some\Path\package\package.zip"
For the detail info, you can refer to the same issue on GitHub.
I used dotnet publish -c Release /p:WebPublishMethod=Package /p:PackageLocation="C:\Temp" for Uno Platform app and it works well
Maybe it is because you put full file name to /p:PackageLocation= instead of the folder?

Visual Studio Online build step PackageLocation being ignored

I have a Visual Studio Online build definition that seems to be misbehaving, but I'm not sure if I've just misconfigured something.
There is a build step which is configured as follows:
Type: Visual Studio Build
Solution: **\mysolutionfile.sln
MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)"
The build runs successfully, and the build log shows the msbuild command is executed as follows:
"C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe" "C:\a\1\s\Code\mysolutionfile.sln" /nologo /nr:false /dl:CentralLogger,(more removed for brevity) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="C:\a\1\a" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="14.0" /p:_MSDeployUserAgent="VSTS_6efdabeb-1c75-43a7-96b2-f40e19a68a35_build_14_122"
As you can see, the package location is correctly set: /p:PackageLocation="C:\a\1\a"
However, later in the build log, the package step shows this log entry:
2017-01-20T05:07:30.9771422Z Executing command ["C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:manifest='C:\Users\buildguest\AppData\Local\Temp\PublishTemp\obj\mysolution55\SourceManifest.xml' -dest:package='C:\a\1\s\Code\mysolutionfile\bin\Release\MSDeployPackage\mysolutionfile.zip' -verb:sync -replace:match='C:\\Users\\buildguest\\AppData\\Local\\Temp\\PublishTemp\\mysolutionfile55\\',replace='website\' -retryAttempts:20 -disablerule:BackupRule]
As you can see, in this case the package is being sent to -dest:package='C:\a\1\s\Code\mysolutionfile\bin\Release\MSDeployPackage\mysolutionfile.zip' - and this is indeed where the zip file ends up.
As far as I can tell, this looks wrong. I want to have the packaged application binaries and files end up in the staging directory, but msbuild is overriding me somewhere and putting them into the source checkout folder.
In case it's relevant, the solution contains two projects: an ASP.NET Core web app that is targeting the full .NET Framework; and a portable class library.
Am I doing something wrong in the build configuration?
I reproduced your issue in my TFS Environment and I got the same result with. The package under the "C:\a\1\s" folder not "C:\a\1\a'.
As a workaround, you could add a Copy files step to copy the package from the source folder to $(build.stagingDirectory) path.
I guess that it did not work as you expected because the variable name should be Build.ArtifactStagingDirectory instead of build.stagingDirectory
Example:
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:Configuration=Release /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
#msbuildArgs: '/T:"MyProject1" /p:OutDir=$(Build.ArtifactStagingDirectory) /nowarn:FS0049'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: MyWebSiteArtefactZIP
There is also another way to Deploy:
If you have created a Publish Profile (you can use Visual Studio for that),
it is also possible to Publish directly from MSBuild, you can put the Web App username/password in the Azure DevOps Pipeline variables and use them:
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:Configuration=Release /P:DeployOnBuild=true /P:PublishProfile="MyPublishProfile.pubxml" /P:Username=$(username);Password=$(password)'

How to deploy project with msdeploy instead of msbuild

Today I use msbuild to deploy a web application to an iis server. How can I do the same with msdeploy (command line)?
MSBuild.exe myproject.csproj
/P:VisualStudioVersion=11.0
/P:Password=pass
/P:AllowUntrustedCertificate=true
/P:DeployOnBuild=True
/P:PublishProfile=deploytest
/P:DeployIISAppPath="Default Web site"
/P:MsDeployServiceUrl=my.server.com
/P:Configuration=Release
It depends what you would like your workflow to be, if you want to package the output and deploy that seperately then you'll need to create a zip file from your build.
Create Package
Add the following to your msbuild command line to create a package:
/p:DeployTarget=Package
/p:PackageLocation=MyProject.zip
/p:CreatePackageOnPublish=True
Deploy Package
msdeploy.exe
-verb:sync
-source:Package=MyProject.Zip
-destination:auto:ComputerName="my.server.com"
You might also want to promote from one deployed site to another.
Clone Site
msdeploy.exe
-verb:sync
-source:appHostConfig="my.server.com"
-dest:appHostConfig="mynew.server.com"
Or you may already have a site that you want to target.
Clone Application
msdeploy.exe
-verb:sync
-source:iisApp="my.server.com/MyApp"
-dest:iisApp="my.server.com/MyNewApp"

Publish web projects with msbuild

I get this error message:
(SetGenerateManifests target) ->
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(4351,5): error : Publish is only valid for 'Windows Application' or 'Console Application' project types. [E:\myproj\myproj.csproj]
running this command line:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild e:\myproj\myproj.csproj /p:VisualStudioVersion=11.0 /t:ResolveReferences;Publish /p:DeployOnBuild=true /p:Configuration=Release-Dev /p:PublishProfile=myapp-Dev-Web /p:DeployOnBuild=true /p:Password=mypass /p:VisualStudioVersion=11.0 /l:FileLogger,Microsoft.Build.Engine;logfile=E:\temp\web-build.txt;Verbosity=Diagnostic
before that I run a command line that succeeds:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild e:\mysln.sln
/p:BuildProjectReferences=true /p:Configuration=Release-Dev
msbuild cannot be used to deploy web projects.
The publish feature in msbuild seems to be used only for database projects.
The solution is to use MSDEPLOY to deploy web projects.