Search code examples
openwrap

Using OpenWrap with Scope


I may not fully understand the wiki article on scoping, so forgive me if this sounds dumb.

Intro:
I have a solution (ABC.sln) with over 40 projects and am trying to implement OpenWrap for package management. So I did the following in the solution's root folder:

o init-wrap -all

That worked fine: I now have a file called SLN.wrapdesc in the solution's root folder. All of the .csproj files in the subfolders contain the OpenWrap targets line.
I then proceded to add the different wraps to the solution with:

o add-wrap -Name xxx

Again, this worked fine: I have some wraps in the wraps folder, and the build doesn't break after removing the old references from the projects.

Problem:
All of the contents of the wraps are going to all of the projects, even for those that don't need it. I would like to be able to specify which wraps go where, eg AjaxControlToolkit only goes into web projects.

What I tried
First, I removed the AjaxControlToolkit from the wrapdesc:

o remove-wrap AjaxControlToolkit

This causes the build to break (as expected). Then I tried the following:
1. Try to add the wrap back with a scope:

o add-wrap -Name AjaxControlToolkit -scope webproject

This simply puts the wrap back in the wraps folder. I then added <OpenWrap-Scope>customscope</OpenWrap-Scope> to the project file, but the build still broke.
2. Try and manually add a file called ABC.webproject.wrapdesc to the root folder. This causes the following error when I try to open the solution:

The "exists" function only accepts a scalar value, but its argument "@(_WrapFile->'%(FullPath)')" evaluates to "D:\Projects\ABC.webproject.wrapdesc;D:\Projects\ABC.wrapdesc" which is not a scalar value.

I guess it doesn't like 2 wrapdesc files. That is strange because the wiki says "...you can add a second descriptor alongside your default descriptor..."

So now I'm stuck. Anyone have any ideas?


Solution

  • The per-msbuild file is really not a recommended approach to managing dependencies. Doing it per project is not quite the design philosophy behind OpenWrap, so the system is not quite optimized for those scenarios.

    If you don't need something from those assemblies then the easiest way to solve it is to not use the references by not using any code from those packages. This solves the problem very easily as nothing will get loaded (or even need to be on disk) if no code has been added to it.

    That said, add-wrap -scope newscope will create an additional .wrapdesc file that will add the new dependency to the new scope, by creating a myProject.newscope.wrapdesc file independently of the original myProject.wrapdesc.

    If you do want to do this per-project, have you tried using the convention-based scoping? Something like:

    directory-structure: src\*{scope: Web=WebProjects}*
    

    Would take any project in a folder child of src containing Web in the name and assign those to the WebProjects scope.

    I know that one has worked fine for my projects so far, although you do have to restart VS as it aggressively caches certain files and will not see the change.

    Customizing the msbuild file itself is not fully tested (and the wiki entry was very much a design spec rather than final documentation, not all of it has been built that way) so it may or may not work. Happy to take a look if you can open a bug ticket on http://github.com/openrasta/openwrap/issues