How to Successfully Publish an ASP.NET Web Application Using MSBuild

Publishing an ASP.NET web application can sometimes feel daunting, especially when your attempts lead to confusing error messages. If you’ve been trying to publish your ASP.NET MVC application locally using MSBuild and encountered the dreaded message: “Skipping unpublishable project,” don’t worry! This blog will guide you through the correct process of publishing your application and ensure that your deployment is smooth and efficient.

Understanding the Error

When you attempt to execute the following NAnt target:

<target name="publish-artifacts-to-build">
    <msbuild project="my-solution.sln" target="Publish">
      <property name="Configuration" value="debug" />
      <property name="OutDir" value="builds\" />
      <arg line="/m:2 /tv:3.5" />
    </msbuild>
</target>

the error message “Skipping unpublishable project.” arises because you are invoking a target that is intended for a different purpose. The Publish target you are trying to use is specifically designed for OneClick deployment, and not for publishing a website directly.

The Right Approach to Publish Your ASP.NET Application

To successfully publish your ASP.NET web application, consider using the AspNetCompiler task instead of the MSBuild task. This task is more suitable for compiling your ASP.NET application into a deployable format.

Steps to Publish using AspNetCompiler

Here’s how to set up the AspNetCompiler:

  1. Create a new NAnt target for ASP.NET Compilation:

    Update your NAnt target to use AspNetCompiler as follows:

    <target name="publish-artifacts-to-build">
        <aspnetcompiler 
            configuration="debug" 
            targetedframework="4.0" 
            virtualpath="/" 
            physicalpath="path\to\your\webapp" 
            outputpath="builds\" 
            debug="true">
        </aspnetcompiler>
    </target>
    
    • configuration: Set this property to debug or release as per your needs.
    • physicalpath: Provide the path to your web application directory.
    • outputpath: This is where the compiled files will be stored.
  2. Adjust your Environment:

    Make sure that your environment is set up to support ASP.NET web application publishing. This includes ensuring that your SDK versions are correct and all necessary dependencies are installed.

  3. Run the Deployment Command:

    With the NAnt target properly set up, run your build. This will compile the ASP.NET application and output it to your specified directory.

Further Resources

For more detailed information on the AspNetCompiler task, refer to the official documentation at MSDN. This page provides insights into the properties and how to utilize them effectively for more complex deployments.

Conclusion

Publishing an ASP.NET web application can be achieved without encountering common pitfalls. By using the right task— in this case, AspNetCompiler— you will ensure that your application is compiled properly and is ready for deployment. If you follow the structured approach outlined in this blog, you will experience a seamless deployment process.

Engage with your development environment intelligently, and avoid deployment headaches in the future!