Skip to content

Consuming wraps from MSBuild

FrozenCow edited this page Sep 2, 2010 · 11 revisions

“Eating tasty wraps from the XML Monster”
- @petemounce

Once a wrap descriptor has been built, it’s time to hook-up your project file to load the dlls at compile time.

OpenWrap provides an MSBuild task responsible for resolving all the required references present in the wrap packages declared in the descriptor.

To make it easier to integrate in a C# msbuild file, OpenWrap also provides an MSBuild target that can replace the standard CSharp target, providing some properties that can quickly modify how a build happens.

The MSBuild target

The quickest way to import the OpenWrap assembly resolver in your solution is to use the MSBuild target.

First, if you start from an empty C# project, you need to shuffle a few things around. This is the recommended folder structure:

  • packageName
    • wraps contains the wrap packages you will rely on
    • src contains your source code
      • packageName-1.0.0.wrapdesc your descriptor files
      • YourProject
        • YourProject.csproj

The /wraps folder is the most important, it will be the repository for all the wrap packages you will use in your solution. It contains a cache folder in which each of the wrap files is automatically uncompressed the first time you use the package. At the very least, you need to have that folder exist, even if it’s empty.

If you’ve installed OpenWrap on your machine, the o shell will be available on your path. The only thing you need to install the OpenWrap package is to execute the following command line while in your project:

o wrap install openwrap

This will automatically install the OpenWrap package and decompress it locally.

Once this is done, you can change the following line from YourProject.csproj:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

with

<Import Project="..\..\..\wraps\cache\openwrap-1.0.0\build\OpenWrap.CSharp.targets" />

This will import the default OpenWrap targets. The reason we have to link directly to the file itself inside the cache directory stems from OpenWrap being deployed as a wrap, and MSBuild not supporting an import using wildcards. Maybe we can come up with a better scenario later on.

The following properties are now available for modification in your project file, should you wish to override the defaults.

Variable Description
OpenWrap-EnableVisualStudioIntegration Enables or disables the modules that integrate with visual studio during a build, such as the resharper integration.
OpenWrap-TargetProfile Describes the profile (net20, net30, net35, etc) used to resolve wrap references. By default depends on the $(TargetFrameworkVersion) parameter.
OpenWrap-ProjectRepositoryPath The location of the project wrap repository.
OpenWrap-DescriptorPath The path to the descriptor file for the current project.

Clone this wiki locally