DLeh
DLeh

Reputation: 24395

msbuild deployonbuild trying to publish different project

I have an MVC site that I am publishing through the command line using the arguments

msbuild.exe /p:DeployOnBuild=true /p:PublishProfile=Test MyProject.csproj

The MyProjectproject has a reference to another web application project MyReferencedProject. This is used to store shared Razor views and other shared code with another web site. (Making the project type as a Web Application was recommended by RazorGenerator so that I get intellisense when working with Razor views) This project functions like a class library, and should never be published.

The issue is that when I run the command above, I get the error that it can't find the Test.pubxml for MyReferencedProject:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4352,5): error : The value for PublishProfile is set to 'Test', expected to find the file at 'C:\Projects\MyReferencedProject\Properties\PublishProfiles\Test.pubxml' but it could not be found.

How can I run msbuild to publish MyProject without it also trying to publish MyReferencedProject?

I found I can work around the issue by adding a Test publish profile for this project, but that means I have to set up some place to put the code when it's published, which really shouldn't be generated at all.

Upvotes: 1

Views: 799

Answers (1)

Matt Brooks
Matt Brooks

Reputation: 1604

Try changing your command line to:

msbuild.exe /p:DeployMyProject=true /p:PublishProfile=Test MyProject.csproj

Then add the following property group to MyProject.csproj before any Import statements:

<PropertyGroup>
  <DeployOnBuild Condition="'$(DeployMyProject)'!=''">$(DeployMyProject)</DeployOnBuild>
</PropertyGroup>

This solution is based on: How to publish one web project from a solution.

Upvotes: 2

Related Questions