简体   繁体   中英

Web Deployment Project / MSBuild - TempBuildDir

When using the Web Deployment Project MSBuild uses the folder '.TempBuildDir' when performing the build. Is it possible to specify an alternative folder?

In C:\\Program Files\\MSBuild\\Microsoft\\WebDeployment\\v9.0 or v10.0 directory is the Microsoft.WebDeployment.targets file where the TempBuildDir property is defined in the _PrepareForBuild target.

Since they use the CreateProperty task to set TempBuildDir it is always set to the hard-coded value even if the property already exists. This could be to eliminate the problem of someone using TempBuildDir property for something else and messing up the build.

You would have to change the Microsoft.WebDeployment.targets file to use a different temp directory.

WARNING: The following is changing a file you don't have control over so use are your own risk.

If you were to change the following lines in the _PrepareForBuild target from

  <CreateProperty Value=".\TempBuildDir\">
    <Output TaskParameter="Value" PropertyName="TempBuildDir" />
  </CreateProperty>

to

 <CreateProperty Value="$(MySpecialWebTempBuildDir)" Condition=" '$(MySpecialWebTempBuildDir)' != '' ">
    <Output TaskParameter="Value" PropertyName="TempBuildDir" />
  </CreateProperty>
  <CreateProperty Value=".\TempBuildDir\" Condition=" '$(MySpecialWebTempBuildDir)' == '' ">
    <Output TaskParameter="Value" PropertyName="TempBuildDir" />
  </CreateProperty>

Then set the MySpecialWebTempBuildDir property in your project file and it should override it. If you don't set MySpecialWebTempBuildDir then it will use TempBuildDir as before.

If you install an update to the web deployment package your changes will get overwritten.

Another solution is to uncomment and override the "BeforeBuild" target of the web deployment project as follows:

<Target Name="BeforeBuild">
<CreateProperty Value=".\TempBuildDirDebug\" Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <Output TaskParameter="Value" PropertyName="TempBuildDir" />
</CreateProperty>
<CreateProperty Value=".\TempBuildDirRelease\" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <Output TaskParameter="Value" PropertyName="TempBuildDir" />
</CreateProperty> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM