How to invoke MSBuild via command prompt?

Nasser Hadjloo picture Nasser Hadjloo · May 2, 2011 · Viewed 74.9k times · Source

I have a website (not a web application) and I want to publish it from the command prompt in the same directory every night.

I don't want to use build automation tools like TeamCity, TFS, or third-party tools like Nant - it should be done with MSBuild. How can I do this?

Update: in the Publish window the only option that should be checked is Use Fixed naming and single page assemblies.

Answer

somatic rev picture somatic rev · May 2, 2011

From your comment, your web project is a web site project and not a web application project.

In this case, 'Publish' target can not be the option but 'AspNetCompiler' is the solution.

Create an xml file with below content and call it from MSBuild.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="PrecompileWeb">
        <AspNetCompiler
            VirtualPath="/MyWebSite"
            PhysicalPath="c:\inetpub\wwwroot\MyWebSite\"
            TargetPath="c:\precompiledweb\MyWebSite\"
            Force="true"
            Debug="true"
            FixedNames="True"
        />
    </Target>
</Project>

Reference to this task is here and you can configure all your un/check options.

FixedName="True" equals the checking of 'use fixed naming and single page...' option.

Then you call this file from MSBuild instead of the solution file.

MSBuild your.xml /p:Configuration=<Debug/Release>

As long as your class libraries are referenced by your web site project, they'll be built together.