Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010: How to publish an ASP.NET web app to a target folder with MSBUILD?

In Visual Studio 2010, you know how you can change your configuration (debug, release, etc), right-click a project in the solution explorer, click publish, and have all the important web app project files for the selected configuration copied to a target folder along with an xdt-transformed web.config? Well, I am looking for the MSBUILD equivalent of exactly that.

My challenge to you: Provide the ONE LINE that I need to execute at my command prompt in order to accomplish this. No third party programs. No tutorial videos. Just a single, straight-up command that I can literally copy from your response, paste into a command window, modify as necessary to support my directory structure, and then hit enter.

If not, then perhaps someone could provide a link to a complete MSBUILD reference showing every command, switch, and value I can use at the command line.

like image 1000
oscilatingcretin Avatar asked Apr 16 '11 01:04

oscilatingcretin


People also ask

How do I publish a program in Visual Studio?

Right-click on the project (not the solution) in Solution Explorer and select Publish. In the Publish tab, select Publish. Visual Studio writes the files that comprise your application to the local file system. The Publish tab now shows a single profile, FolderProfile.


1 Answers

Put the below to ProjectPublish.MSBuild.xml file (change PropertyGroup as needed):

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Publish"> 
    <PropertyGroup>
        <ProjectFile>Path\To\Web.csproj</ProjectFile>
        <PublishDir>Path\For\Publish\Output</PublishDir>
        <TempDir>Path\To\Temp\Folder</TempDir>
        <BuildConfig>Release|Debug</BuildConfig>
    </PropertyGroup>

    <Target Name="Publish">
        <MSBuild Projects="$(ProjectFile)"
                 Properties="Configuration=$(BuildConfig);WebProjectOutputDir=$(PublishDir);OutDir=$(TempDir)\;BuildingProject=true"
                 Targets="ResolveReferences;_CopyWebApplication" />
    </Target>
</Project>

Calling this from command line (or .bat file) should do the trick:

%windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe ProjectPublish.MSBuild.xml
like image 177
Ramunas Avatar answered Oct 12 '22 14:10

Ramunas