I've a very complex solution in c# containing about 20 projects, each of them control a device since it is a driver.
In many cases those projects use similar structures/code (for example everyone as a connect method, a retrive data method and so on).
Is there a tool to analyze the code and create a general "Skeleton" that can be reused?
You can easily create a project template from an existing project from the File>Export Template menu. The process is described in How To: Create Project Templates.
There is no tool that can decide what to include in a skeleton project, as this depends on knowledge of what each project actually does, which parts that can be generalized and which have to be project specific.
You can use duplicate analysis in Visual Studio or Resharper to find repeated code, but this won't tell you what should be in a template and what shouldn't.
What you can do, is:
Extract common functionality in a separate project that all device projects will reference
Create a template from one of the device projects.
Use template parameters to customize the resulting template.
Step #1 will result in a much simpler template, that is easier to customize
I would like to see all references of a given method. I mean references in C# sources and views (.aspx, .ascx, .cshtml). Is there a way to do that? A VS2012 setting or a plugin?
If you changed a method and you use it in your Views and don't know which one, you can always change the MvcBuildViews attribute in .csproj.
<MvcBuildViews>true</MvcBuildViews>
Resharper is an excellent tool that allows you to find all usages (this includes Views) in your solution.
http://www.jetbrains.com/resharper/
There are also some alternatives to resharper:
CodeRush: http://www.devexpress.com/Home/Try.xml
JustCode: http://blogs.telerik.com/blogs/posts/09-11-18/code-just-code-justcode.aspx
VisualAssistX: http://www.wholetomato.com/
The only one free is VSCommands:
http://visualstudiogallery.msdn.microsoft.com/d491911d-97f3-4cf6-87b0-6a2882120acf/ , but i don't know for sure if it has that functionality.
There is also a customer feedback here: http://aspnet.uservoice.com/forums/41201-asp-net-mvc/suggestions/3090767-make-find-all-references-search-in-mvc-views, in case you want to track it's status.
I have an open source ASP.NET MVC application there is an add-in called T4MVC and I can see all the html, aspx, images, Controllers, views files are integrated, I wonder how it works.
If I create a file(aspx,html...) has it to be integrated manually to that template(T4MVC) or by default it get mixed? could someone please advise of how to get this(T4MVC) ans MVC do work together since I am new in ASP.net MVC.
T4MVC is a template that Visual Studio will compile and execute when you save the file in the editor (there are tools to automate this; search for AutoTT or Chirpy to check them out).
The template scans your project to find controllers, views, images, etc. and generates code that allows you to reference those items programatically elsewhere in your code. Whenever you add, remove or rename a resource (any of the items the template looks for) the template must be executed again to regenerate the code output.
The advantage of T4MVC (over the use of strings to reference things) is that you get compile-time checking, as well as intellisense and refactoring support.
I have an idea to create some sort of extended Immediate Window VS plugin. I've noticed that when I want to test something (like new Regex or DB reqest) I tend to create new console app for this. The idea is to create project that is not included in solution and references current project and has all using directives from current file. So I'll have all advantages of code editor: usings (no full class names), syntax highliting, IntelliSense, multiline commands, other plugins (R#/CR).
Is this possible?
Option A: Write those in a test-project added to your solution
Option B: Create a console application added to your solution
Create a build-script that only builds the projects you want to give to your customers.
To gain some ideas: look at http://mvcstarter.codeplex.com/ (point 9)
I'm new to visual studio, coming from Delphi.
I have a directory tree full of .cs files (root is \Common).
I also have a directory tree full of Applications (root is \Applications)
Finally, I've got a tree full of Assemblies (root is \Assemblies)
I'd like to keep my .cs files in the Common tree and all the environment voodoo (solutions, projects, settings, metadata, debug data, bin, etc.) in the Assmblies tree. So, for a simple example, I've got an assembly called PdMagic.Common.Math.dll. The Solution and project is located in \Assemblies\Common\Math. All of its source (.cs) files are in \Common\Math. (matrix.cs, trig.cs, mathtypes.cs, mathfuncs.cs, stats.cs, etc.)
When I use Add Existing Item to add matrix.cs to my project, a copy of it is added to the \Assemblies\Common\Math folder. I just want to reference it. I don't want multiple copies laying around. I've tried Add Existing Item, and used the drop down to "Add link" rather than just "Add", and that seems to do what I want.
Question: What is the "best practice" for this sort of thing? Do most people just put those .cs files all in the same folder as the project? Why isn't "Add link" the default?
Thanks!
You can just use Add As Link by clicking on the little down arrow to the right of the add button from Add-->Existing Item command...
Whilst I realise this is not in an answer to the original question (which regards best practices), I present this answer in order to save the time of others who have been directed here by the misleading title of this question.
The "best practice" in this case, is to not fight the tool. It allows you to do what you want, but you'll get more work done and be able to focus on code if you just let the IDE organize your project for you.
I would create an empty solution project called PdMagic.Common
This will give you a file structure like
PdMagic.Common\
PdMagic.Common\PdMagic.Common.sln
then I generally add a src and libs folder (via the file system, not VS)
inside the libs folder, i would place all my third party dependencies, and the src folder would hold all of my projects
PdMagic.Common\
PdMagic.Common\PdMagic.Common.sln
PdMagic.Common\libs
PdMagic.Common\libs\nunit
PdMagic.Common\src
Next, in Visual Studio, I would right click on the Solution I just created, and click "Add -> New Project", I would specify that I wanted it created in the \src folder and call it PdMagic.Common.Math
Now my folder structure would look like this
PdMagic.Common\
PdMagic.Common\PdMagic.Common.sln
PdMagic.Common\libs
PdMagic.Common\libs\nunit
PdMagic.Common\src
PdMagic.Common\src\PdMagic.Common.Math
PdMagic.Common\src\PdMagic.Common.Math\PdMagic.Common.Math.csproj
PdMagic.Common\src\PdMagic.Common.Math\Class1.cs
Then, as you add classes to your PdMagic.Common.Math project, they will go in the folder with the project file. This is how the IDE has the opinion we should work, and I think most developers go with it because trying to get any other layout on the file system would require too much fighting with the IDE. I know it can be hard to come from a different convention, and you instinctively want the same conventions in the new environment. However, if you stick with the conventions, (right or wrong in your opinion) you'll get more done because you won't be trying to force the IDE to do things the way you think they should be done.
I think that the 'best practice' is to have those 'common' routines into an assembly that you can reference instead of pulling the source files into a bunch of different projects. You could add it as a pre-built assembly with "Add reference..." or by including a project for that assembly and adding a reference to the project (also done inthe "Add reference..." dialog).
This is one of those things that seems like a bit of work to set up initially (and it may be), but it generally pays off in the long run.
If you want to "reference" matrix.cs in your project, don't use Add Existing Item, create a reference ("Add Reference") to the class library or object that matrix.cs is a part of. If you don't want (or can't use) the library or object that matrix.cs is part of, then the Add Link is how you would get to it, but seriously I've never used that particular feature.
None of the developers I have ever worked with in .NET isolate their .cs files in separate folders. The only kind of segregation like that that I have seen as a practice is in MVC, where the models, views and controllers are in their own folders.
Because you want to reference matrix.cs in the project, dont just use AddExistigItem, create a new referene to the class.
VS has some useful extensions for this:
http://vscommands.com
and ProjectsLinker: http://visualstudiogallery.msdn.microsoft.com/5e730577-d11c-4f2e-8e2b-cbb87f76c044?SRC=VSIDE
and SourceShare: http://visualstudiogallery.msdn.microsoft.com/aa5d54dd-0b05-4689-ad2f-634e86de327f?SRC=VSIDE
In Visual Studio 2019 it is:
Right click on a project
Add
Existing item
Select file
Expand menu next to Add
Add As Link