5

I am creating a build script to automate the publishing of our web projects to a testing machine.

I have a msbuild script which successfully does this, however when it is running it generates an error for each project in the solution stating that "The target "_WPPCopyWebApplication" does not exist in the project".

It is correct because in each of my project files I do not import the relevant .targets file that contains this function.

If I do change each of the project files to import the .targets file then instead of the errors I get a warning for each project stating that

MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" cannot be imported again.

It was already imported at "MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets (354,3)". This is most likely a build authoring error. This subsequent import will be ignored.

At the moment I import the relevant .targets files at the top of my build script:

<Project ToolsVersion="4.0"
     xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project ="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"/>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets"/>

Is there a way to prevent the error stating that the "_WPPCopyWebApplication" is not present in the project file without generating the warning stating that there are duplicate imports after I add it to each project file?

Why do the projects need to import the targets file if it is imported at the top of my build script?

Edit:

I am currently using _WPPCopyWebApplication like this:

<Target Name="Publish" >
<RemoveDir Directories="$(OutputFolder)" ContinueOnError="true" />
<MSBuild Projects="myproject.csproj;anotherproject.csproj" Targets="ResolveReferences;_WPPCopyWebApplication" Properties="WebProjectOutputDir=$(OutputFolder);OutDir=$(WebProjectOutputDir)\" />
</Target>

Which I got from here and here:

Aesir
  • 932
  • 1
  • 15
  • 30
  • Have you tried to add to the MSBUIld task properties CleanWebProjectOutputDir=False ? – sll Aug 17 '11 at 11:09

1 Answers1

4

You are getting that error because Microsoft.WebApplication.targets already imports Microsoft.Web.Publishing.targets.

http://www.asp.net/web-forms/tutorials/deployment/web-deployment-in-the-enterprise/building-and-packaging-web-application-projects

How Does the WPP Work?

The Microsoft.WebApplication.targets file in turn imports the Microsoft.Web.Publishing.targets file. The Microsoft.Web.Publishing.targets file essentially is the WPP. It defines targets, like Package and MSDeployPublish, that invoke Web Deploy to complete various deployment tasks.

Community
  • 1
  • 1
efisher
  • 223
  • 4
  • 12
  • and the actual solution is to copy "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Web" to the target machine. I was trying to use only Visual Studio Build Tools without VS installed, so I copied it where I had copied the WebApplications folder: "\\BuildMachine\C$\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\Web" – Siderite Zackwehdex Mar 06 '19 at 09:28
  • The original problem was that @Aesir was importing Microsoft.Web.Publishing.targets unnecessarily in their .csproj ... Yes, it would be ideal if Microsoft included many more things in the VS Build Tools package rather than forcing hacky workarounds. Here we are, 2019, still having to install VS on build servers. – efisher Mar 06 '19 at 18:31
  • I agree with you, but I didn't know if that was actually useful for VS publication on IIS. Anyway, I had multiple issues with targets and I had to copy them when related to Web, WebApplications, NuGet, Wix, etc. Temoving them all would probably cause issues. – Siderite Zackwehdex Mar 07 '19 at 10:20