MSBuild fails with two packages
Asked Answered
P

1

10

Okay this is a fantastic bug. I have a 2012 solution that executes MSBuild on a 2012 TFS server. The parameters passed to the "MSBuild Arguments" field in build process template are as follows:

/p:DeployOnBuild=true /p:PublishProfile=ProfileForProjectA /p:PublishProfile=ProfileForProjectB /p:VisualStudioVersion=11.0

And the error I get back from TFS is....

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets (4435): The value for PublishProfile is set to 'ProfileForProjectA', expected to find the file at 'C:\Builds\1\Solution\Solution\Sources\Solution\ProjectB\Properties\PublishProfiles\ProfileForProjectA.pubxml' but it could not be found.

In other words it would appear that the build server expects each publish profile (*.pubxml) to be in each PublishProfiles folder. The publish method for both projects is "File System."

The only thing that solves it for me is adding ProfileForProjectA to the PublishProfiles folder for ProjectB and vice versa, but that doesn't seem like a very elegant solution. Can anyone reproduce this behavior? Does anyone have a more elegant fix? Am I missing something?

Thanks in advance.

Positively answered 9/1, 2013 at 0:28 Comment(0)
C
17

When you pass properties via the command line they are global MSBuild properties. Because of that they are passed to each project within a .sln file. Web projects are the only ones which respond to those specific properties.

In your scenario if you have two projects that you want to build+publish in a .sln file you would need to create a profile in each web project with the same name, say "MyProfile". They do not need to contain the same info, they can each have their own unique set of settings. They just need to share a name.

Then when you build.

msbuild.exe mysolution.sln /p:DeployOnBuild=true /p:PublishProfile=MyProfile /p:VisualStudioVersion=11.0

When each web project is built the publish process for MyProfile in that project will be invoked.

If you have scenarios where you want to specify different values for PublishProfile then you will need to create an MSBuild script instead of building the .sln file. There's a few different ways that you could solve it but they all involve some MSBuild.

Disclaimer

Do not use this technique for live servers... but its great if you are publishing to an intermediate location before the final publish.

If you build+publish more than 1 project in a solution you may publish one project when the other one doesn't even build. This is because the publish process is actually an extension of the build process. Here is an example.

You have ProjectA and ProjectB in a solution, when you build with the properties above ProjectA will be invoked and it will build and publish. Then it will move on to ProjectB which will build and publish. The build for ProjectB may fail and ProjectA would have already been published.

Copra answered 9/1, 2013 at 9:14 Comment(1)
You may also target a specific project. See my solution here: #16892030Ops

© 2022 - 2024 — McMap. All rights reserved.