Matt Brailsford
Matt Brailsford

Reputation: 2237

How to change WebProjectOutputDir default location?

Does anybody know, on a per project basis, whether you can set the WebProjectOutputDir in Visual Studio. I want to be able to have it so that when i hit Ctrl + Shift + B it automatically builds my web project to a specific directory, but I also need to be able to override this in my build script.

Upvotes: 9

Views: 9613

Answers (2)

Michael A.
Michael A.

Reputation: 49

I ran into this when using Visual Studio for Mac, compiling an Umbraco project. Building would issue the following error:

Error MSB4044: The "KillProcess" task was not given a value for the required parameter "ImagePath"

It was returning an empty value for WebProjectOutputDir when compiling Rosyln, etc. Only the web project in the solution was compiling these items, so I edited the web project csproj file manually, and added the following to the global at the top of the file:

    ...
    <WebProjectOutputDir>.\</WebProjectOutputDir>
</PropertyGroup>

Problem solved.

Upvotes: 7

Sayed Ibrahim Hashimi
Sayed Ibrahim Hashimi

Reputation: 44322

It is unnecessarily awkward to correctly do this based on the way that Microsoft.WebApplications.targets defines the _CopyWebApplication target and how Microsoft.Common.targets treats the OutDir and OutputPath properties.

If you want to change that in the project file itself then you should:

  • Declare the property WebProjectOutputDir after the import to Microsoft.WebApplications.targets
  • Declare the property OutDir before the import to Microsoft.WebApplications.targets

There are a few reasons why you have to do this.

Microsoft.WebApplications.targets will override any declaration of WebProjectOutputDir if it is declared before the import statement. Therefore it has to come after.

Also inside of Microsoft.WebApplications.targets the _CopyWebApplication is defined as follows:

<Target Name="_CopyWebApplication" Condition="'$(OutDir)' != '$(OutputPath)'" >
  ....
</Target>

Taking a look at the condition you will see that the target will not be executed if OutDir and OutputPath are equal to the same value. You cannot just change OutputPath because OutDir is based on OutputPath, so you have to change OutDir and make sure that it is before the import to that file because other properties are built based on that property.

Less than ideal, but hopefully that helps you.

Upvotes: 16

Related Questions