Jacob Lewallen

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Projects in Visual Studio
machine-projects

In the world of Visual Studio we have solutions and projects. I create lots of projects. At Eleutian we have close to 40 projects in our main solution. Keep in mind, that at any given time I only have a subset those loaded depending on which feature I am working on. Machine, a relatively recent undertaking, is growing and is already up to 13 projects. I've been thinking of the higher level organization of my software development process and come to some conclusions. As I'm working on a piece of software there are two primary reasons for why I create a new project:

  1. Do I need a place to store tests for another project? Nearly half of all the projects I create are test projects. :)
  2. Do I have a group of classes that can be packaged and then later re-used? I see this situation as an application of Separation of Concerns.

Number two is particularly important. Projects to me are a useful way to create distinct, reusable collections of code. Separate projects are good ways of isolating heavy dependencies. Storing static code in a separate project is a good way to decrease time spent during rebuilds. In a client-server situation it's handy to place code common to both tiers in a shared project. Projects are wonderful tools for good design and lately I've been wishing I had more control over them.

Visual Studio enforces a strict one assembly per project convention. Remember, we can change preprocessing settings, target CPU, debug/optimization settings, and a few other things via Build Configurations. In my experience the one-to-one convention creates some problems:

  1. A lot of project configuration is duplicated. Most of my projects have the same core build configuration and only a few are different and then only in minor ways. I've often wished I could create my Build Configurations and then reference them from my projects.
  2. They get in the way! For me, projects are usually created once and forgotten. Most of my project-level changes are rare. Yet, they are everywhere in the user interface. Thankfully with R# I can GotoType around them, but I still feel like they stand between me and the code. I'm weird that way I guess. My focus is the code, not the projects.
  3. In order to build or use code under two different project-configurations I'm usually required to perform some kind of trickery. Refactoring code into a common project that is referenced by two others, for example. I've even had to create two csproj's in one directory that both include the same code, this is awkward.

I want two things. I want something slightly lower on the hierarchy than a project - a sub-project. We could, for example, group tests into a sub project and the production code into another. Much of the existing project configuration would be shared among them, including dependencies and the active build configuration. Additionally, and this is huge, I would get rid of the parent-child relationship between projects and code. Projects would become external configuration that would be applied to sets of code.

I used to do lots of Java development and because of the atomic nature of the .class files this kind of structure was very easy. A single project can result in multiple jar files from which classes can be included/excluded at will. I'm really proposing a more shallow solution hierarchy. How sub-projects would look in VS I can't say. Thankfully, this is not a limitation of C# or .NET. The fact is, we can probably achieve a very rudimentary implementation of this via some clever tweaking of the standard .targets files.

I'm curious about how much I would like this approach in practice. You never know how much you'll like something until you've tried it. I do know that when I used Java I didn't wish for the VS approach. Any thoughts? Is this too much? Is this not enough?


Posted 04-01-2008 5:39 PM by jlewallen
Filed under: , ,

[Advertisement]

Comments

shawn wrote re: Projects in Visual Studio
on 04-01-2008 9:22 PM

I've been thinking about this as well, but mostly in the context of some sort of more sophisticated reference system. I'd like to be able to have "soft" references to virtual projects (i.e, vendor code or shared libraries). I think the two ideas have a natural overlap.

jlewallen wrote re: Projects in Visual Studio
on 04-01-2008 9:50 PM

shawn: I'd like to hear more about the soft references. I've had some thoughts regarding how we handle 3rd party dependencies now. Especially in the Castle/NH world where things can get a little messy and I've been wanting to clean things up.

Blair wrote re: Projects in Visual Studio
on 04-01-2008 11:33 PM

You know you could use the "Link" feature inside of Visual Studio. Just open up the "File Open" dialog and instead of just pressing the Open button hit the drop down arrow next to it and there is a selection to "link" the file, i.e. this gets translated into the MSBUILD file also.

jlewallen wrote re: Projects in Visual Studio
on 04-02-2008 1:23 AM

Blair: Yeah, the link feature is useful in some situations (We've used it once, honestly though it's got a bad smell for me). My goal though is to only maintain one collection of source code, and "Link" at a higher level, not just individual files. If that makes sense. I suppose I could sort of fake it by having a master project with all my source, and then the projects that I'm actually building that are links (albeit very messy ones cause of the limitations of Links)

Skwr wrote re: Projects in Visual Studio
on 04-02-2008 5:47 AM
Dew Drop - April 2, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - April 2, 2008 | Alvin Ashcraft's Morning Dew
on 04-02-2008 9:46 AM

Pingback from  Dew Drop - April 2, 2008 | Alvin Ashcraft's Morning Dew

jlewallen wrote re: Projects in Visual Studio
on 04-02-2008 12:53 PM

Skwr: Ayende's onto something in situations where the project division isn't for re-use in software external to the solution. For example, sure, I could bunch up some of the projects in Machine into one super-project, but that sort of defeats the purpose for breaking them up. I do agree that it's a nice thing to consider regarding the tests, because the tests generally aren't distributed/shared.

Bryan Reynolds wrote re: Projects in Visual Studio
on 04-02-2008 1:01 PM

There does not seem to be an easy answer.

Scott wrote re: Projects in Visual Studio
on 04-02-2008 1:58 PM

To me, it seems like you're back to writing a makefile/build task and doing the linking yourself. That's kind of the ultimate control.

Although I think you may be a little OCD about this. ;) But then again I've never had more than 10 projects in any solution I've worked on.

Joshua Flanagan wrote re: Projects in Visual Studio
on 04-02-2008 3:55 PM

I'm with Scott - isn't this just a matter of creating a separate MSBUILD .proj file that does your bidding? There's your "Projects would become external configuration that would be applied to sets of code."

I assume you don't use Visual Studio as your primary way to produce builds anyway...

I think I'm either completely missing your point or this post is an April Fools joke.

jlewallen wrote re: Projects in Visual Studio
on 04-02-2008 6:37 PM

Scott: I'm definately OCD about development. Hehe.

Joshua: No joking in this post. And yes, it's a matter of creating separate build files, if you're willing to live that way.

The problem is with VS. I want VS to give me more flexibility. I use VS as my primary IDE and have done my absolute best to avoid duplication into separate build files while still being able to use VS. I've even considered moving to a generated csproj situation a la Mono's Prebuild tool, although I'm not sure that will give me all I want.

Joshua Flanagan wrote re: Projects in Visual Studio
on 04-02-2008 9:47 PM

I am definitely willing to accept that I'm missing the point.

I was not advocating duplication with separate build files - they would be used in addition to the build files that Visual Studio likes, but without any duplicate data.

For example, to solve your "build multiple configurations in one shot", it would look something like:

<Project DefaultTargets="Build" xmlns="schemas.microsoft.com/.../2003">

<ItemGroup>

<ConfigurationsToBuild Include="Debug" />

<ConfigurationsToBuild Include="Release" />

</ItemGroup>

<Target Name="Build">

<MSBuild Projects="MyApp.csproj" Properties="Configuration=%(ConfigurationsToBuild.Identity)" />

</Target>

</Project>

As you suggest, I feel like a lot of what you are asking for can be accomplished by overriding some of the default targets (I wouldn't change the original CSharp.targets file).

Do you want it to "look" different in VS, or would you be satisfied with it just behaving differently?

Visual Studio pretty much just does an "MSBuild /target:build", so you can really change the Build target to behave however you want.

As for sharing build configurations, that might be accomplished by getting the settings how you want them, then copying the correct PropertyGroup out of the .csproj, putting it in your own shared Configurations.proj file, which you then Import into all of your other .csproj files.

Once you get a build file with the overrides and imports you like, you can create a Project Template based on it so that it shows up in the File | New Project dialog.

Dru wrote re: Projects in Visual Studio
on 04-02-2008 10:27 PM
jlewallen wrote re: Projects in Visual Studio
on 04-03-2008 12:04 AM

Joshua:  No I think you're getting the point. I think a proof of concept like you've got that plays nicely with VS would be a good place to start. Eventually, VS would have to change. It's fine to have the convention out of the box, and it be default sure. I think there's some valuable UI things that could be done to ease things and make it a nice of looking at large pieces of software.

Dru: No, I hadn't seen that. I'm pretty happy with my directory structure. It's what happens under src with all of the csproj's that concerns me. Mine evolve to look very similarly to his though as the directories are needed. Albeit my naming is slightly different.

Jay R. Wren wrote re: Projects in Visual Studio
on 04-03-2008 11:25 AM

The compilers support netmodules. I always wished that VS supported compiling to netmodules and REFERENCING netmodules instead of dlls. Then you could have "netmodule projects" and treat them like projects. The netmodule would get compiled into your DLL on build of the parent project. It would make mixing C# and VB.NET code a little easier, which is something that I want more now that VB.NET has XML Literals.

Patrick Smacchia wrote re: Projects in Visual Studio
on 04-28-2008 12:00 PM

> Do I have a group of classes that can be packaged and then later re-used?

I am very surprised that nobody mentionned the namsepaces. Project/assemblies are physical stuff and should never be used to just group some classes. Only physical reason can lead to new physical artefact (such as tiers that live on different machine separation, or interfaces for IoC).

> I want two things. I want something slightly lower on the hierarchy than a project - a sub-project.

Previously I wrote Project/Assemblies because VisualStudio enforces a one-to-one relationship between the two concepts and this is indeed very unfortunate. You won't solve this with .NET modules that are another physical concepts but more with a mapping between projects and namespaces.

DotNetKicks.com wrote Projects In Visual Studio
on 07-17-2008 1:53 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Add a Comment

(required)  
(optional)
(required)  
Remember Me?