TeamCity MSBuild Web Site publishproj
Asked Answered
B

3

5

I have a Web Site project which I am trying to deploy via TeamCity and WebDeploy.

Because this is a Web Site and NOT a Web Application I do not have a .vbproj or .csproj file.

I have come to the conclusion from this post here that I need to create a .publishproj file as MSbuild uses this as it's build file.

However when TeamCity invokes MSBuild it bails with the following error:-

Failed to start MSBuild.exe. Failed to detect default target(s) in the project file C:\TeamCity\buildAgent\work\d9dda73c7948f14a\MainSite\website.publishproj. Please define targets explicitly in the build configuration options on TeamCity Web UI. Project does not define DefaultTargets or InitialTargets.

I have looked inside the .publishproj file and there is no Target defined.

I have also followed Troy Hunt's You're deploying it wrong articles for a Web Application and this works fine.

Can anybody suggest how I Web Deploy a Web Site (NOT Web Application) from Team City ?

Bunkum answered 6/6, 2014 at 10:53 Comment(0)
A
6

I never worked with web-site-not-a-web-project so take it with a grain of salt.

website.publishproj seems to be create the moment you touch Build > Publish Web Site menu in Visual Studio and imports Microsoft.WebSite.Publishing.targets which is good cause it's the same similar targets file imported by your normal web projects (Microsoft.WebApplication.targets) and both of which import Microsoft.Web.Publishing.targets.

Unlike any project created by Visual Studio it doesn't have a DefaultTargets = Build nor OutputPath property, so you need to explicitly specify Targets in MSBuild build step with any targets defined in Microsoft.WebSite.Publishing.targets or Microsoft.Web.Publishing.targets.

You can call your standard msbuild website.publishproj /t:Package /p:OutputPath=.\ to generate the .cmd and corresponding .zip in obj\Debug\Package. Then just call the .cmd or pass the .zip to the msdeploy.exe -source:package=.zip or try to do /t:Build /p:DeployOnBuild=true but I suspect you'd be missing a crap ton of properties predefined by your normal web project.

Edit:

There seems to be a circular reference somewhere and you end up with a package containing 2/3 copies of itself in PackageTmp\_PublishedWebsites, so play around with OutDir, OutputPath, PackageDestinationRoot and so on to get rid of the duplicates. Create a sample web project and read through the .csproj and .targets to get the idea.

Edit:

If you go through the publishing wizard you will also get App_Data\PublishProfiles\Foo.pubxml as well that's being read via PublishProfileName/WebPublishProfileFile, importing it would save time on some typing. This might be relevant.

Edit:

The import of proper web targets seems to be a new feature in 2012/2013, with 2010 you would need to use aspnet_compiler.

aspnet_compiler -v Foo -p . -f obj
msdeploy -verb:sync -source:iisApp=%CD%\obj -dest:iisApp="Default Web Site/foo"
Asarum answered 6/6, 2014 at 15:46 Comment(0)
B
2

I found out in the end that for some reason I had to explicitly set the target to Rebuild in Team City for Web Site projects.

Bunkum answered 10/6, 2014 at 8:53 Comment(0)
S
2

Set the Build Step property Targets of the Visual Studio (sln) runner to Package.

Assuming you have the following directory structure:

\{Team City Working Directory}
  |
  |-- MyWebSite
  |    |-- App_Code
  |    |-- App_Data
  |    |    |
  |    |    \--PublishProfiles
  |    |         |
  |    |         \-- MyWebSite-Package.pubxml
  |    |
  |    | ... Other files and directories
  |    |
  |    |-- MyWebSite.publishproj
  |
  |-- SomeOtherLibraryProject
  |
  \-- MyWebSite.sln

Then, if you are specifying the solution file in the Solution File Path field of the build step, you should specify the following Command Line Parameters for the build step:

/p:PublishProfile=MyWebSite\App_Data\PublishProfiles\MyWebSite-Package.pubxml

However, you can also specify .\MyWebSite\MyWebSite.publishproj for the Solution File Path property of the build step; and if you do so, then you should specify the following Command Line Parameters instead:

/p:PublishProfile=App_Data\PublishProfiles\MyWebSite-Package.pubxml

The PublishProfile property is a relative path from the project or solution file specified in the Solution File Path property.

Scope answered 21/9, 2014 at 0:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.