Azure web sites with Paket
Learn how to deploy Azure websites using Paket instead of NuGet. Step-by-step guide with .deployment and build.cmd configuration.
Whoever worked with Microsoft Shop knows about nuget. It is a package manager for anything and everything related to .Net. And it is getting better and better with versions coming in. But again it is nowhere near the maturity needed to work with projects having many small projects. Things get cranky soon.
Now, there is a better option as per my opinion called Paket. Very easy to get started. And so damn reliable. A couple more commands to learn but I guess it is ok. It cleans up most of the mess of nuget. And the best thing—no XML.
Now, I normally throw anything and everything to Azure websites. Just do experiments and it's free. Mostly I put projects in Github and pull them into Azure. Easiest way to test something or anything which needs network.
Now, you can have Paket instead of nuget with minimum changes. There is a detailed article written by Scott Hanselman that you can find.
But for your existing or new web project, what are the minimum requirements?
You need to create .deployment in the root of your project. It will tell Azure's build system to not go with defaults. (I guess the build system is called Kudu.)
In that file, copy and paste the code below:
[config]
command = build.cmd
Two lines to tell it to use build.cmd to build the project.
Now, we obviously need the build.cmd file in root.
And here is the code:
@ECHO OFF
setlocal
echo ====== Restoring packages... ======
if not exist .paket\paket.exe (
.paket\paket.bootstrapper.exe
)
.paket\paket.exe restore
if not %ERRORLEVEL% == 0 (
echo ====== Failed to restore packages. ======
exit 1
)
echo ====== Building... ======
msbuild /p:Configuration=Release
if not %ERRORLEVEL% == 0 (
echo ====== Build failed. ======
exit 1
)
if not "%DEPLOYMENT_TARGET%" == "" (
echo ====== Deploying... ======
xcopy /y /e <project name> "%DEPLOYMENT_TARGET%"
)
The code is very much self-explanatory.
First, pull the latest paket.exe, then restore packages. msbuild is there, so just use it. And the age-old xcopy to copy built files to the deployment target.
Bang! It's done. You can check things out with the log tail or console on the Azure portal.
If you want to go a little bit advanced and want kind of a build system, then you can always try FAKE. But if you're in a great hurry and don't want to waste time with nuget issues, go for Paket.
Happy Packaging!!!
Frequently Asked Questions
Paket is a package manager for .NET projects that offers better reliability and cleaner configuration compared to NuGet, especially for projects with many small dependencies. Unlike NuGet, Paket eliminates XML configuration mess and provides a more mature solution for managing complex project dependencies.
You need to create two files in your project root: `.deployment` file that tells Azure to use a custom build command, and `build.cmd` that contains the actual build instructions including Paket package restoration and MSBuild compilation.
The build.cmd file first bootstraps and restores packages using Paket, then compiles your project with MSBuild in Release mode, and finally copies the built files to the Azure deployment target using xcopy. It includes error checking at each step to ensure the build process fails cleanly if any step encounters an issue.
Yes, if you need more sophisticated build automation, you can use FAKE (F# Make), which provides a full build system. However, for quick deployments and straightforward projects, Paket with a simple build.cmd script is sufficient and requires less setup time.