Creating a new project with OpenWrap

With all this discussion of OpenWrap stuff, we’ve not covered yet how easy it is to create a new project in OpenWrap and get it off the ground.

For OpenWrap to function, you don’t need much. You need a /wraps folder at the root of your code, a descriptor file, and optionally a version file.

Creating a new package

The easiest way to create a new project is to use the init-wrap command with a name for your new package or project. As I use git, I’ll also ask it to generate the .gitignore files for me.

PS C:\src> o init-wrap newProject -git
# OpenWrap v1.0.0.0 ['C:\Users\sebastien.lambla\AppData\Local\OpenWrap\wraps\_cache\openwrap-1.0.0.19240580\bin-net35\OpenWrap.dll'] Specify either the path to the projects you want updated or -all to find all projects automatically. Copying 'openwrap-1.0.0.19240580' from 'System repository' to 'Project repository' Copying 'openfilesystem-1.0.0.19074013' from 'System repository' to 'Project repository' Copying 'sharpziplib-0.85.5.452' from 'System repository' to 'Project repository' Package 'newProject' initialized. Start adding packages by using the 'add-wrap' command.

Your project structure is now going to be fully created, together with ignore files and the first couple of packages you need.

Adding a new project

imageNow you can go and open Visual Studio, and create a new project in the /newProject/src folder that was created earlier. Any will do, I’ll add a new bog standard “Class Library” project and name it NewProject.Core.

Note that you can use any C# project type, OpenWrap doesn’t care much. VB and other languages can be supported, as soon as someone ask for them we’ll add that.

One of the things that makes OpenWrap different is also that you can create a Visual Studio 2008 or Visual Studio 2010 project, it doesn’t matter either. And you can choose a .net 2, .net 3.5 or .net 4 project type, it will all still work.

OpenWrap, meet Project, Project, meet OpenWrap

Next, we need to inject OpenWrap in the build process of that project. Again, not much to do there, it’s a one-liner. Go into the folder you created earlier, and execute the init-wrap command with the –all parameter. This instructs OpenWrap to find all ‘.csproj’ files and update them.

PS C:\src> cd newProject
PS C:\src\newProject> o init-wrap -all
# OpenWrap v1.0.0.0 ['C:\src\newProject\wraps\_cache\openwrap-1.0.0.19240887\bin-net35\OpenWrap.dll'] Package descriptor found. Project 'C:\src\newProject\src\NewProject.Core\NewProject.Core.csproj' updated to use OpenWrap.

If you return to Visual Studio, you’ll be greeted by a dialog box letting you know the project was modified. Reload it, and you’ll be ready to go.

Writing some code

We’ll write a log4net class in our newly-created project.

  1. namespace NewProject.Core
  2. {
  3.     public class Appender : log4net.Appender.TextWriterAppender
  4.     {
  5.  
  6.     }
  7. }

As you can see, ReSharper tells us it doesn’t recognize that class. Let’s add the package for log4net.

PS C:\src\newProject> o add-wrap log4net
# OpenWrap v1.0.0.0 ['C:\src\newProject\wraps\_cache\openwrap-1.0.0.19240887\bin-net35\OpenWrap.dll'] Wrap descriptor found. Project repository present. Dependency added to descriptor. Copying 'log4net-1.2.10' from 'nu' to 'System repository' Copying 'log4net-1.2.10' from 'nu' to 'Project repository' Making sure the cache is up-to-date...

If you now go back to your solution, you’ll notice that the red lining is now gone, and you can build your code as if you had added the reference yourself. If you don’t use Resharper, rebuild your project as normal and see that the code compiles.

Packaging a package

You now have functional code you’re happy with, and you want to share your package. Fear not, for again, it’s a one-liner.

PS C:\src\newProject> o build-wrap -quiet
# OpenWrap v1.0.0.0 ['C:\src\newProject\wraps\_cache\openwrap-1.0.0.19240887\bin-net35\OpenWrap.dll'] Output found - bin-net40: 'C:\src\newProject\wraps\_cache\log4net-1.2.10\bin-net20\log4net.xml' Output found - bin-net40: 'C:\src\newProject\src\NewProject.Core\obj\Debug\NewProject.Core.dll' Copying: bin-net40 - C:\src\newProject\wraps\_cache\log4net-1.2.10\bin-net20\log4net.xml Copying: bin-net40 - C:\src\newProject\src\NewProject.Core\obj\Debug\NewProject.Core.dll Package built at 'C:\src\newProject\newProject-0.0.1.19243541.wrap'.

Note that I’ve used the –quiet parameter to silence the MSBuild output. You can of course see the whole output by simply removing that parameter.

Publishing a package

Only thing left to do to start sharing your code is to publish it. I use the Network Share feature for publishing my packages, so it’s dead easy.

PS C:\src\newProject> o publish-wrap netshare .\newProject-0.0.1.19243541.wrap
# OpenWrap v1.0.0.0 ['C:\src\newProject\wraps\_cache\openwrap-1.0.0.19240887\bin-net35\OpenWrap.dll'] Publishing package 'newProject-0.0.1.19243541.wrap' to 'netshare'

And I can verify that the package was indeed published properly by listing the packages in the remote.

PS C:\src\newProject> o list-wrap -remote netshare
# OpenWrap v1.0.0.0 ['C:\src\newProject\wraps\_cache\openwrap-1.0.0.19240887\bin-net35\OpenWrap.dll'] - newProject (versions: 0.0.1.19243541)

As always, don’t forget you can get help on each of those commands by using the get-help command.

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Carl Lewis

    This example doesn’t work out of the box. You need follow the instructions at http://goo.gl/oo6uq before it works.

    • http://codebetter.com/sebastienlambla/ Sebastien Lambla

      Thanks for your message.

      I am currently travelling and and e-mails may have to be responded to after my return.

      For customers with a support contract, please contact your regular customer-specific email address that has been communicated to you (usually clientname@caffeine-it.net).
      For account enquiries or renew your support contract, please contact our accounting team at accounts@caffeine-it.net.
      For any other enquiry, we will get back to you as soon as possible.

      Thanks

  • Sebastien Lambla

    @Francois thanks I’ve updated it :)

  • http://www.vwd.co.za Francois Botha

    Hi,

    On https://github.com/openrasta/openwrap/wiki
    The ‘cd newProject’ command is a crucial command, but missing.

  • http://richarddingwall.name Richard Dingwall

    Hey Seb, I’d like to see an article about migrating an existing solution to OpenWrap. For example, will it pick up existing referenced assemblies and resolve them back to OpenWrap packages?