Frage

I would like to create a multi-project template for Visual Studio 2008 which contains two projects that access the same source files (single source for mobile and desktop development). The following multi-project template:

<TemplateContent>
    <ProjectCollection>
        <ProjectTemplateLink ProjectName="Client.CF">Client\Template.CF.vstemplate</ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="Client.FF">Client\Template.FF.vstemplate</ProjectTemplateLink>
        <!-- some other projects -->
    </ProjectCollection>
</TemplateContent>

will create this structure:

Solution folder
  - Client.CF
    - Client.CF.csproj
    - Other project files
  - Client.FF
    - Client.FF.csproj
    - Other project files

For single source the following structure is required:

Solution folder
  - Client
    - Client.CF.csproj
    - Client.FF.csproj
    - Other project files

After some playing around with the template XML I doubt that it is possible to create such a template. Has anyone already achieved this?

War es hilfreich?

Lösung

edit by OP...

Do Not Do This - It Won't Work.

subtitle:

can I have my week back pleez?

Why? Well, many files in projects have relationships with each other. Blindly wild-card linking to them will include them in a build but the relationships will be lost.

Even ignoring that fundamental flaw, the range of possibilities of files to include and exclude is ...well, a lot. Don't build fragility and technical debt into your project before it starts.

Using Multiple build configs in a single project is a better Solution (pun intended). See https://stackoverflow.com/a/4457508/492 for the sort of thing I am talking about.

I'll leave this wrong answer here just in case it saves you a trip down a blind alley, or at least raises your awareness of this issue. Hey, just think of it as practice. Hey, at least I'm learning. Sometimes.

as an aside, wild-card linking things like commonly-used utility classes such as extension methods can be a good thing. Just be aware of the implications.

.
.

the original story....

I just did this to build 6 (yes - SIX) versions of the same app. AutoCAD - they love to break the API every 3 years. Don't get me started. I'm also building for other compatible apps so AutoCAD is only 3 versions. I digress.

Here is how I did it. I had an extra project called zSourceCode which has - the source code. Duh. I also has the AssemblyInfoForAllProjects.cs file. Each project also has an additional AssemblyInfo.cs project with the attributes AssemblyTitle & AssemblyDescription, only because I wanted to identify the build version in the name and description.

The other projects linked to the zSourceCode project files like so...

<Compile Include="..\zSourceCode\**\*.*" Exclude="..\zSourceCode\Properties\AssemblyInfo.cs;..\zSourceCode\bin\**\*.*;..\zSourceCode\obj\**\*.*;..\zSourceCode\**\*.csproj;..\zSourceCode\**\*.user;..\zSourceCode\**\*.vstemplate;..\zSourceCode\readme.txt;..\zSourceCode\**\*.lsp;..\zSourceCode\**\*.scr;..\zSourceCode\**\*.ico;;..\zSourceCode\**\*.txt"> <Link>Src\%(RecursiveDir)%(Filename)%(Extension)</Link> </Compile>

Ignoring the fact that I doubled up on readme.txt (with *.txt), and you probably won't have any LISP (*.lsp) nor startup scripts for AutoCAD (*.scr), that's the gist of it.

Using this wildcard syntax, you can add files and folders to the source project and they will propagate to all your build projects. You can add any code specific to a project within that project itself.

I added Extension methods to patch the behavior changes between the versions. These live outside the Solution, in a central place so I can patch all my AutoCAD-related stuff-ups in one place. This was tricky because I wanted to reference it by an absolute path. The only way to get VS to generate the absolute paths in the compile links was to put that stuff on another drive (or map a folder to another drive letter).

The rest of Multi-project templates is as per http://msdn.microsoft.com/en-us/library/ms185308.aspx which is probably where you got the first chunk of code from.

Look out for this rather annoying problem with getting a surprise layer of folders between the solution & the projects: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/11d7da1d-40cf-4b5c-ac27-d7fe504062a8/ . You can solve that by writing an Iwizard implementation but that has to go in the GAC and blahblahblah. I just manually shuffle them and edit the .sln file in Notepad++. NP++ is handy for editing project files too. VS just reloads the projects when you change them, unless you break them. Did I mention source control?

Also, the first time you generate the solution, you'll have to close it and re-open it to see the links in the Solution Explorer.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top