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
Related
I am trying to use VSTS to publish a project that contains an Azure Function. My MSBuild step is passing the following build arguments
/p:Configuration=Release /p:DeployOnBuild=true
/p:WebPublishMethod=Package /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\MyFunctions.$(Build.BuildNumber)-dev.zip"
/p:DeployIisAppPath="Default Web Site"
This is giving me a Zip where the folder structure of \Content\D_C\a\3\s\MyFunctions\obj\Release\net461\PubTmp\Out. The Out directory has the content I need and what I'd expect to be the root
The folder structure I need to push a Zip is
As documented Here
Can anyone advise on what I am doing wrong here?
Thanks
I do it in a 2 step process
build with a VSTS Build task with settings /p:DeployOnBuild=true /p:DeployTarget=Package;CreatePackageOnPublish=true
ZIP it with a VSTS Archive Files task. Here I leave the option to Prefix root folder name... unchecked.
Sample:
With Azure App Service Deploy task and Publish using Web Deploy option, it won’t remain the folder structure and the content files will be in wwwroot folder of azure app service. So you don’t need to care the package folder structure.
Otherwise, you can publish the app through FileSystem publish method (e.g. /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish), then zip files through Archive files task, after that you can deploy it through Zip push deployment way (Azure CLI or PowerShell)
Zip push deployment for Azure Functions
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?
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)'
I'm attempting to create a build that will build my solution, apply web.config transforms as necessary and finally copy desired output (a built web api project) to the artifacts area of the build.
I'm using the Deployment...Azure WebApp Template with the Azure App Service Deploy step disabled (as we're in the middle of a move to Azure), with the following build arguments in the build step:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\" /p:AutoParameterizationWebConfigConnectionStrings=False
All works as expected, apart from the structure of the resulting zip file, which has the following structure:
{ZipFileName}{ProjectName\Content\C_C\a\1\s\Api{ProjectName\obj\Release\Package\PackageTmp...{BuildContent}
I'd like the content to be at the root of the published zip file if possible. Is the best way to manipulate the content of $(build.artifactstagingdirectory) using Powershell or a number of the other built in build tasks?
You don’t need to worry about it, because it won’t keep the folder structure (Just the files and folders in PackageTmp folder) after deploy to web server (e.g. IIS, Azure Web App)
If you still need to just include the files in PackageTmp folder, you can add build step to archive file to zip file through Archive Files step.
For Visual Studio Build step, specify /p:DeployOnBuild=true to MSBuild Arguments.
Hi I need to publish my code using MSbuild.exe and create a package of the publish code to a location.
Need to understand how target file will work and the arguments I need to pass while calling the MSbuild.exe
If you are looking to keep code in a folder the better way to do it is to package it since your intentions are to deploy it to IIS later. That way the deployment will process will be easier and clean.
Below is the command to create and save package to desired location:
msbuild "Your\Solution\location\YourSolution.sln" /t:build /P:configuration="Debug-Dev" /p:platform="Any CPU" /p:VisualStudioVersion=14.0 /p:DeployOnBuild=True /p:CreatePackageOnPublish=True /p:DeployOnBuild=True /p:DeployTarget=Package /p:PackageLocation="\wherever\you\want"