MSBuild error MSB4057: The target “Package” does not exist in the project.

Every three weeks we release an update to our websites and web services.  To make this release easier, I created a batch file that would build the projects and deploy each one to our four web servers.  The last few times I tried this, my batch file failed running this command:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe C:\Projects\Portal\Portal1.vbproj /nologo /verbosity:minimal /t:Package /p:Configuration=Release

C:\Projects\Portal\Portal1.vbproj : error MSB4057: The target "Package" does not exist in the project.

So then each time, I would have to manually deploy the web sites with One-Click Publish.  Today, I decided to resolve this problem.

Because the Internet has a great memory and because the nature of deploying Visual Studio has changed frequently and recently, it was very difficult to determine what was the current best way to do the automated task that I wanted. 

The first promising solution was to install a project called “CommunityTasks” and import it into your project.  Did that.  Didn’t work.  Read further and learned I needed to install the Azure SDK (This would haunt me for a long time).  Still, none of the example command lines worked.

Then I learned that some publishing settings had been moved from the project file to the publishing profiles.  Fine, I could handle that.  I created a new publishing profile that created a package.  However, I couldn’t figure out how to execute that publishing profile from the command line.

In the end, I decided I would create the deployment packages manually in VS with One-Click Publish, then execute a batch file that would run the package’s deploy.cmd files for each project to each server.  This would actually result in a faster deployment because I wouldn’t have to wait for each project to build in the deployment batch file.  And using the /k switch, I could launch multiple deployments at once.  For example:

start cmd /k "Portal1.bat"
start cmd /k "Portal2.bat"
start cmd /k "Portal3.bat"
start cmd /k "Portal4.bat"

And each batch file for the project would install to each server:

c:\Build\Package\portal1.deploy.cmd /Y /M:http://server01/MSDeployAgentService /U:deploy /P:deploy -enableRule:DoNotDeleteRule
c:\Build\Package\portal1.deploy.cmd /Y /M:
http://server02/MSDeployAgentService /U:deploy /P:deploy -enableRule:DoNotDeleteRule
c:\Build\Package\portal1.deploy.cmd /Y /M:
http://server03/MSDeployAgentService /U:deploy /P:deploy -enableRule:DoNotDeleteRule
c:\Build\Package\portal1.deploy.cmd /Y /M:
http://server04/MSDeployAgentService /U:deploy /P:deploy -enableRule:DoNotDeleteRule