Deploy to remote server via command line - visual-studio

I have a Visual Studio 2013 project. I need to deploy it to remote Windows Server via command line, is this possible?
I tried the following command:
MSBuild.exe C:\BuildAgent\work\e1434fd989e26b76\WebService.csproj /T:Package /P:Configuration=Release
This packages the project for me. Now what should I do to deploy it to the server via command line?

Create a new custom publish profile from visual studio. After creating it validate the connection from visual studio.Save this profile.Now in Properties/PublishProfiles there will be the new publish profile.pubxml.
After that try this.
msbuild "PATH_TO_SOLUTION_FILE" /p:DeployOnBuild=true /p:PublishProfile="PATH_TO_PUBLISH_PROFILE" /p:AllowUntrustedCertificate=true /p:UserName=USER_NAME /p:Password=PASSWORD
If you are executing the above from solution file path then just mention the solution name and publishing profile name. There is no need to give the entire path.

You can define a publishing profile and deploy by calling an msbuild.exe with:
/p:DeployOnBuild=true /p:PublishProfile=Foo
This is described here:
http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/command-line-deployment

Related

Explanation on specific differences between my click once publish when done via command line and from Visual Studio

I am trying to understand why is my WindowsForm app publish behaving differently, when done via command line and via Visual Studio's Publish.
The differences are:
In my command line publish, a copy of the .exe is placed in the top-directory publish folder, while it is not there, when published via VS
In my command line publish, the .application file is missing in the [Application Files] folder, while it is there when published via VS
A screen shot illustrating the exposed above:
Anyone has any idea why does this happen ? I have tried playing with the publish settings, but still without success.
Below is what my command line statement looks like (ran via Jenkins):
Explanation on specific differences between my click once publish when done via command line and from Visual Studio
That because some features are done by Visual-Studio and not by the MSBuild command line. So the click-once-deployment behaves differently when it's executed from the command-line.
When you publish via command line, only Project.exe and Setup.exe are copied to the deployment folder. You can switch the deployment folder by property PublishDir:
msbuild "ProjectName.csproj" /target:publish /p:Configuration=Release;PublishDir=D:\TestPublishFolder
When you publish from Visual Studio, Visual Studio will do some more features, including Application Files folder and .application file into deployment folder.
If you want to have the same publish result as Visual Studio when you publish via command line, you can custom target to achieve it.
See ApplicationFiles folder missing when ClickOnce publish with command line for more detailed info.
Hope this helps.

TeamCity publish using Visual Studio 2015

I've read many articles on publishing from TeamCity using various versions of Visual Studio. I'm currently using v.9.1.7 of TeamCity and Visual Studio 2015.
I have my 3 build steps on check-in:
Clean & Rebuild
Unit Test
Publish
When I check in my files I get a Tests Passed success message:
I can tell from here something isn't right as I'm expecting it to say something about publishing. When I look at the Build Log I see the following:
[12:48:22][API\API.sln] Publish [12:48:22][Publish] MSBuild [12:48:22][MSBuild] API\API\API.csproj: Build target: Publish
[12:48:22][API\API\API.csproj] _DeploymentUnpublishable
My Publish Build Step is setup this way:
In my API project in Visual Studio I can publish to the correct location on the network. Here is my publish profile:
I'm not sure what I'm missing. I'm expecting the Publishing build step to work like when I click the Build->Publish menu item in Visual Studio.
I'm guessing that I'm missing something or misunderstanding what the publishing build step is supposed to do.
Any help is appreciated.
I was able to get it to work after days and days of searching. I found part of the answer here on Stack Overflow. The trick was to get it to work from the MSBuild Command Line:
C:\TFS\project\myProject\APIproject>msbuild apiproject.csproj
/p:DeployOnBuild=true
/p:PublishProfile="Properties\PublishProfiles\DEV.pubxml"
/p:VisualStudioVersion=14.0
Once I got this running several times I was able to create a Build Step in Team City (see this question/answer) and I set the following:
Build file path: <location of the apiproject.csproj>
MSBuild version: Microsoft Build Tools 2015
MSBuild ToolsVersion: 14.0
Run platform: x86
Command Line Parameters: /p:DeployOnBuild=true /p:PublishProfile= "C:\TFS\API\API\Properties\PublishProfiles\DEV.pubxml" /p:VisualStudioVersion=14.0
IIRC, publishing from TeamCity requires certain files or alternatively VS installed on the build agent (which really isn't recommendable). Have you copied the necessary files to the build agent?
Where are artifacts location defined.
And you can use Tentacles for publishing build into various environments.
I guess, you need to look towards artifacts configurations.
You can use MSBuild runner to Deploy your Application/API
Add Command line parameter :
/t:Clean /p:DeployOnBuild=true /t:build /t:publish /p:PublishProfile=C:\_works\teamcity\publishprofiles\Publiush_Profile.pubxml /p:VisualStudioVersion=12.0
PublishPrfile URL should be your publish profile path.
This will work for you.
VS will probably find your publish profile with just the name, like:
/p:DeployOnBuild=true;/p:PublishProfile=DEV; very useful if you run more than one build agent.
And if you're deploying to an IIS you might need to add AllowUntrustedCertificate=true;

Publish doesn't work from build definition VS2012

What I thought would be simple is not. All I am trying to do is get MSBuild to copy website files to another server after my build.
In my Build definition Under Process --> Advance --> MSBuild Arguments I put
/p:DeployOnBuild=true /p:PublishProfile=WebsiteProfile
It builds fine but it never copies files to destination
BUT when I run this command locally, IT WORKS!!!!!
msbuild /p:DeployOnBuild=true /p:PublishProfile=WebsiteProfile
I have VS 2012 installed in Build Server so I think all the necessary files are there.
What is the problem?
UPDATE 1
Output in build log file
Run MSBuild for Project
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /nologo /noconsolelogger "C:\Builds\1\MyProject\MyProject\src\MyProject.sln" /nr:False /fl /flp:"logfile=C:\Builds\1\MyProject\MyProject\src\MyProject.log;encoding=Unicode;verbosity=detailed" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:PublishProfile=WebsiteProfile /p:VisualStudioVersion=11.0 /m /p:OutDir="C:\Builds\1\MyProject\MyProject\bin\\" /p:RunCodeAnalysis="False" /p:VCBuildOverride="C:\Builds\1\MyProject\MyProject\src\MyProject.sln.vsprops" /dl:WorkflowCentralLogger,"E:\Microsoft Team Foundation Server 11.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Detailed;BuildUri=vstfs:///Build/Build/64;InformationNodeId=20178;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;TFSUrl=http://abc-tfs-p:8080/tfs/defaultcollection;"*WorkflowForwardingLogger,"E:\Microsoft Team Foundation Server 11.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Detailed;"
REPRODUCTION STEPS
Created new website project
Made sure it worked on local machine
using development server
Checked code in TFS
Created a build definition using all the default settings Under the Process -->
Advance --> MSBuild Arguments I put
/p:DeployOnBuild=true /p:PublishProfile=WebsiteProfile
The publish profile copies the changeset to a remote server.
Installing the Web Tools 2012.2 update on the build server fixed this issue for me after I read this post and Scott Gu's Blog. I don't have Visual Studio installed on the server but installing the update got my DeployOnBuild working. I hope that helps.

Deploying .NET with Jenkins/Hudson

I've been using Jenkins/Hudson CI for deploying my .NET web site project. I've been using the MSbuild plugin to build my project, and then xcopy to copy it out to the server.
I've noticed if I use the publish feature in Visual Studio I get a different set of files. I've got the config transforms working, but I end up with all the .cs files and a winmerge compare shows the binaries being different.
So, I'd like to either get Jenkins working just like the publish feature, or confirm that an xcopy deploy is functionally the same thing.
I've had good experiences with using Web Deploy and as a final build step with Jenkins running a bat file containing:
msdeploy.exe -verb:sync -source:package=%PACKAGE% -dest:auto,ComputerName=%TARGETHOST%
You'll have to install the web deploy package on your build server and the extention on IIS.
I'm using the MSBuild Jenkins plugin to build and then deploy the project. As mentioned in other answers, you need to have Web Deploy installed.
In the project configuration page in Jenkins, you need to add the following to the Command Line Arguments field:
/p:Configuration=Debug /p:DeployOnBuild=true /p:PublishProfile=publishProfileName
Of course, you need to first create the publish profile, either in VS or by exporting it from IIS and you also need to specify the solution file path in the MSBuild Build File field.

Build Web Deployment Package From Command Line

Is there any way to build deployment package for a Web Application using Visual Studio 2010 CommandLine ?
I think this has what you are looking for
MSBuild "MyProjectName.csproj" /T:Package /P:Configuration=Staging;PackageLocation="D:\Vishal\Package.zip"
I got this from this site:
http://vishaljoshi.blogspot.com/2009/02/web-packaging-creating-web-packages.html

Resources