How to use a pubxml file for an ASP.NET project?
Trying to put a VS2015 ASP.Net web application solution we have here into TeamCity for build purposes. Currently it is "released" by having a pubxml profile setup that defines an output folder location, and then someone within Visual Studio going Build -> Publish <sln> and choosing that profile. This produces a set of files in the desired target folder that we then zip up and effectively xcopy to the target server. We are not using WebDeploy packages.
All I want to do in TeamCity is effectively replicate the same Publish to a directory feature, so I can then have another step to do the same zipping etc for publication via Octopus Deploy in our case.
However I have found a confusing lack of documentation around this and other bemused users.
For instance, I know that from a VS command prompt on my machine I could type this command line (where I have a specific profile setup to publish to called TeamCity):
msbuild MyProject.sln /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=TeamCity
On the TeamCity 2017.1 build server we also have VS 2015 installed. I setup a Visual Studio (sln) runner step similar to that mentioned on this page in Step 2: https://confluence.jetbrains.com/pages/viewpage.action?pageId=74845238
I left it with the default target of Rebuild, Configuration of Release, Platform of Any CPU. I tried specifying command line parameters of /p:DeployOnBuild=true /p:PublishProfile=TeamCity - and then seeing the warnings in the log I switched these to system.DeployOnBuild and system.PublishProfile variables instead.
The "good" news is that it does compile the application, producing a bin subfolder for the dlls. The bad news is that it isn't executing the "publish" aspect whereby it uses the TeamCity.pubxml file to copy all the relevant content and bin subfolder to the desired <publishUrl> folder location. There are no warnings or errors - it just looks like all it is doing is compiling the application and not doing any kind of "publish".
What am I doing wrong? What is the "magic" required to replicate Build -> Publish sln that is done by Visual Studio in a TeamCity server?
Please sign in to leave a comment.
Hello Grant,
This actually seems to be more VS question then TeamCity one. I am not a VS expert, so here is the generic approach to alike problems:
Try to find a way to do the task from a command prompt. Make sure it works on the TeamCity agent machine, under the same user TeamCity agent runs under, with the same environment the agent receives. If necessary, run the TeamCity agent under a different user or tweak it's environment. Then configure the same action in a TeamCity build. You can start from using a command-line runner and if that works, try dedicated runner (like MSBuild) if applicable. There are some more details on the process in our related notes.
This basically maps for your case as follows:
If msbuild MyProject.sln /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=TeamCity works fine form the command line when run on the agent machine under agent's user, make sure command line step with "custom script" option and the same command line in a TeamCity build behave as expected, then try using MSBuild runner with the parameters as is ("/p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=TeamCity") put into "Command line parameters".
Hi Yegor, thanks for the reply.
I followed some of those steps and found the issue. Turns out our TeamCity server only had the community edition of VS 2015 installed on it, not the same full edition the developers use.
In particular it was missing the C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web folder which contains Microsoft.Web.Publishing.targets.
Thanks again for the pointers...