I am working on creating a custom Visual Studio template for multiple project types. I would like to be able to add reference across the projects in the solution. e.g. MVVM solution where View, Model and ViewModels are each in their own projects. I'd like to have the View have reference to the ViewModel project and the ViewModel project to have reference to the Model project.
Only documentation I can find on MSDN calls for strongly named assemblies to be referenced.
http://msdn.microsoft.com/en-us/library/ms185290.aspx
I am able to get partially there, by modifying the .cproj file using some of system parameters, but this is heavily dependent on naming conventions etc. for instance I can have the Model project referenced in the ViewModel project because the concatenation of the $safeprojectname$ and "Model" makes the correct assembly name. But I cant get reference of the VM in the V, nor can I add any references to any testing projects.
<ItemGroup>
<ProjectReference Include="..\$safeprojectname$Model\$safeprojectname$Model.csproj">
<Project>{30C01E8B-96AE-45B4-A7B5-8F7BDCA4BDAB}</Project>
<Name>$safeprojectname$Model</Name>
</ProjectReference>
</ItemGroup>
Does anyone know how I can go about achieving this in the template?
Thanks.
I dont know if this is the correct way to do this, but this is what I did. I ended up opening the config file in a text editor and replacing/adding the appropriate project references as necessary. By using appropriate naming conventions I was able to programatically create the project files, sub folders etc.
Related
Is there a way to have visual studio add my helper classes (preferably with the correct namespace) anytime I create a new project. For example all of the extension methods, conversions etc. Its a pain to add them every time I start a new project.
Thanks
I'm in VS2012
There are 2 ways:
create a project template
create a set of library
My preferred way is to create a set of library I reuse in all of my project.
I dividet it with different scope for different kind of projects:
MyLib.Core, MyLib.Web, MyLib.Winforms, MyLib.Nhibernate etc etc
I distribute them with nuget so I can easily handle update and versioning
I have an MVC3 project in VS2010 (Project A) and I want to reference an assembly in one of my other projects (Project B). Project B outputs to \bin\Debug and \bin\Release. I want to add a reference to the proper Project B assembly, based on the configuration of Project A. Is there a way to do this without having to include Project B in Project A's solution? I've always included the project in my solution if I've needed to do this in the past, is this the only and best option?
IMO adding the project to solution is much better if you have access to the project, if you want to make the reference point to different file locations based on the current configuration you can open up the csproj file in a text editor and modify the Reference hint by introducing a macro and the reference path will vary accordinlgy. For example you can do something like this in A.csproj
<Reference Include="B,...">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ProjectB\bin\$(Configuration)\B.dll</HintPath>
</Reference>
and when you reload the project and view the reference properties you will see that the path changes with the selected configuration.
Is it possible to create a project template containing three projects?
I've built a sample project for my client which contains the basic structure for all their new applications. It would be sweet to be able to create a project template from it to make everything a lot easier.
Projects in the solution
ProjectName.Abstractions
ProjectName.Services
ProjectName.WebClient
What I really would like is a solution template =)
There are no solution templates, but there are multi-project templates:
http://msdn.microsoft.com/en-us/library/ms185308(v=VS.100).aspx
If you want to create a solution which contains three project as above. Just follow method of creating multi-project template.
And then in .csproj file of main project,
replace
<ProjectReference Include="\ProjectName.Services\ProjectName.Services.csproj">
<Project>{7D31A904-BA57-4CDA-XXXX-XXXXXXXXXXX}</Project>
<Name>ProjectName.Services</Name>
</ProjectReference>
with below code,
<ProjectReference Include="\$safeprojectname$.Services\$safeprojectname$.Services.csproj">
<Project>{7D31A904-BA57-4CDA-XXXX-XXXXXXXXXXX}</Project>
<Name>$safeprojectname$.Services</Name>
</ProjectReference>
My team is creating some standard VS solution templates. We have a well-defined project structure, resources, etc. that we need to use every time we start a new project and this is the perfect solution. The basics work nicely.
However, as well as defining folder structure (etc.) it would be nice to be able to import a number of projects from VSS/TFS. We have a number of shared assemblies that will be used by all projects and it would be awesome to add a reference to these projects when creating a new project via our template. Can anyone tell me if this is possible and, if so, how it can be achieved?
I think there are 3 types of items you might want to templatize (is that a word?).
New Solution
New Project added to a solution
New item added to a project
I'm not sure whether its possible to add existing projects to the solution that is created when a project template is run. http://msdn.microsoft.com/en-us/library/ms185308.aspx shows how to create multiple project templates. You may have to either manually add them to the solution or create a script that modifies the .sln file to do that part.
Adding an assembly reference to either a project or item template is easily doable. The project template is pretty simple since you just need to modify your .vstemplate file for the project template(s). See http://msdn.microsoft.com/en-us/library/ms171405.aspx for reference.
Adding a new assembly reference when you add a new item from a template is a bit harder but can also be done. See http://msdn.microsoft.com/en-us/library/ms185290.aspx for more.
Have fun!
In the past I have created ItemTemplates for classes that I regularly use in VS2008. I want to create a template for a solution that will have two projects, a Web Site and a Class library.
I have not been able to find any clear instructions on how to do it. I am not sure if it can be done. Does anyone have any links to a possible solution.
Thanks
There are detailed instructions on MSDN for creating custom project templates in VS2008.
-Edit-
There is no such thing as a "Solution Template." There are Item Templates (for new files), and Project Templates. However, I think what you may be looking to do is to create a specific type of Project Template called a Multi-Project Template.