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 v188.8.131.52 ['C:\Users\sebastien.lambla\AppData\Local\OpenWrap\wraps\_cache\openwrap-184.108.40.20640580\bin-net35\OpenWrap.dll'] Specify either the path to the projects you want updated or -all to find all projects automatically. Copying 'openwrap-220.127.116.1140580' from 'System repository' to 'Project repository' Copying 'openfilesystem-18.104.22.16874013' 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
Now 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 newProjectPS C:\src\newProject> o init-wrap -all# OpenWrap v22.214.171.124 ['C:\src\newProject\wraps\_cache\openwrap-126.96.36.19940887\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.
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 v188.8.131.52 ['C:\src\newProject\wraps\_cache\openwrap-184.108.40.20640887\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 v220.127.116.11 ['C:\src\newProject\wraps\_cache\openwrap-18.104.22.16840887\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 v22.214.171.124 ['C:\src\newProject\wraps\_cache\openwrap-126.96.36.19940887\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 v188.8.131.52 ['C:\src\newProject\wraps\_cache\openwrap-184.108.40.20640887\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.