Create a general "skeleton" from a c# project - c#

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

Related

VS2017 Community Create New Scaffolding

I want to develop my own custom scaffolding in VS2017 Community for Controllers and Views in an MVC5 project (not using .NET Core), but I am having a little trouble with it.
I've copied the templates from this location into my project under CodeTemplates:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding
However, I don't want to modify the existing templates, but create my own new ones.
If I try to add a t4 template under CodeTemplates like MyController\Controller.cs.t4 or AddController\MyController\Controller.cs.t4, it will not show up as an option in the menus if I try to right-click on my Controllers folder and add a new Controller or New Scaffolded Item.
Firstly, if I build something like Controller.cs.t4, how do I create a new file from it as say HelloWorldController.cs? Can't seem to find where to look. These are good articles, but I'm having trouble finding what to do about having a t4 template generate a different filename like VS does.
https://msdn.microsoft.com/en-us/library/dd820620.aspx
https://msdn.microsoft.com/en-us/library/bb126478.aspx
What I would like to basically do, is right click on a Model, click a context menu button in VS, and have it call some code I would write that looks at the public functions of the Model via Reflection and procedurally generates the Controller and Views from it using my own templates and places them in the appropriate subfolders.
I may also want it to involve a dialog with other controls, much like the existing Scaffolding menu options work when using an EF Context. Looking at the existing templates that involve EF Context they call this line:
<## ScaffoldingAssembly Processor="ScaffoldingAssemblyLoader" #>
I'm not sure where that sits and how to create my own and reference it is the question.
I may also want an entirely separate template implementation of what exists under CodeTemplates\MvcView that may become a partial view of an SPA page, allowing me to call the CRUD methods via AJAX instead of having it on its own page.
This is already getting a little bit out of hand, and I'm unsure whether this is actually one question or multiple. I'm asking for basically one essential function, but it seems to be composed of several questions: how to process a T4 C# template at design time into a new filename, how to do so with some code that VS understands (does this require VISX knowledge?) and generate the necessary dialogs to set the parameters and run the necessary T4 templates to create files, and how to add that to the standard MVC project right-click context menu (is VISX the solution for this?). I keep asking about VISX because when I look "Custom Command" in a VISX project it's saying it wants to add it to the Tools menu, I don't want it there but on Project's context menu the same way as Controllers, is that only a matter of running Tools -> Customize?
I'm just getting started looking into VISX right now, very excited about it, but there's lots to cover of course.

How to share code and resources between projects

I have two projects named Project 1 and Project 2. I am porting my application from iOS to WP8 and I have ported my iOS_Project 1 to WP8_Project 1. In iOS I have the flexibility to add the files as references and thereby I can achieve code reuse. I would like to perform the same process in WP8, but I couldn't find proper help and here's the question. (Here I want to refer all the classes, images and xaml files like MainPage.xaml)
I know pretty sure about one thing that wpf/forms/.NET projects differ with WP8 structure. Please do provide some help.
Thanks.
When you have add your item to one project, select the option to Add Existing Item to the other project. Navigate to the item you want to add and then you should find a drop-down arrow on the appropriate button to allow you to add the item as a link. That means that there will only ever be one copy of that item but it will be used in both projects.That said, if possible, I would suggest that you break the common functionality out into a library project that you then reference in both the other projects. If you create a portable library then you could use it in a Windows 8 app as well.
You can use references in Visual Studio 2012 - there is no problem. However, PCL (Portable Class Library) is a better solution. Here is example how to add files as link in Visual Studio 2012.

Generate code as Windows Forms do with .designer.cs

I think I have a big problem.
I have a two projects solution.
First one is UI project.
Second one in an Algorithms Service.
I need to generate (or overwrite) a class (fileUI.cs) in UI part just before compiling it.
The main idea is that when you edit a class in de Services part (fileSA.cs) and you build the solution just a moment before the class in the UI part (fileUI.cs) is updated with Services part class information (fileSA.cs), and then, compiled.
I think its similar what VS does with the .designer.cs of every form(user control...)
I dont know if its possible...
Thanks a lot
You need T4 Template Here
Code Generation and T4 Text Templates
Visual Studio has a mechanism called single-file generators / custom tools that targets exactly this use case: generating a file (fileUI.cs in your case) when another file has changed (fileSA.cs).
Refer to the MSDN article Implementing Single-File Generators to learn how such a custom file generator is written.
P.S.: While this would be the appropriate mechanism, I don't think that it will work across the project boundary.
You can add a custom msbuild target in your project (right click on project -> edit project file). See msdn for more info about msbuild targets. You can run custom tasks as part of this target. A way to generate code is using T4 templates. More info here on running t4 templates as part of the build process. Oleg Sych has a lot of detailed explanations on T4 and is kind of the authority on the matter, so his site is a good read to start.

Is it possible to create 'invisible' project using Visual Studio addin?

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)

What is the best practice to segment c#.net projects based on a single base project

Honestly, I can't word my question any better without describing it.
I have a base project (with all its glory, dlls, resources etc) which is a CMS.
I need to use this project as a base for othe custom bake projects.
This base project is to be maintained and updated among all custom bake projects.
I use subversion (Collabnet and Tortise SVN)
I have two questions:
1 - Can I use subversion to share the base project among other projects
What I mean here is can I "Checkout" the base project into another "Checked Out" project and have both update and commit seperatley. So, to paint a picture, let's say I am working on a custom project and I modify the core/base prject in some way (which I know will suit the others) can I then commit those changes and upon doing so when I update the base project in the other "Checked out" resources will it pull the changes? In short, I would like not to have to manually deploy updated core files whenever I make changes into each seperate project.
2 - If I create a custom file (let's say an webcontrol or aspx page etc) can I have it compile seperatley from the base project
Another tricky one to explain. When I publish my web application it creates DLLs based on the namespaces of projects attached to it. So I may have a number of DLLs including the "Website's" namespace DLL, which could simply be website. I want to be able to make a seperate, custom, control which does not compile into those DLLs as the custom files should not rely on those DLLS to run. Is it as simple to set a seperate namespace for those files like CustomFiles.ProjectName for example?
Think of the whole idea as adding modules to the .NET project, I don't want the module's code in any of the core DLLs but I do need for module to be able to access the core dlls.
(There is no need for the core project to access the module code as it should be one way only in theory, though I reckon it woould not be possible anyway without using JSON/SOAP or something like that, maybe I am wrong.)
I want to create a pluggable environment much like that of Joomla/Wordpress as since PHP generally doesn't have to be compiled first I see this is the reason why all this is possible/easy. The idea is to allow pluggable themes, modules etc etc.
(I haven't tried simply adding .NET themes after compile/publish but I am assuming this is possible anyway? OR does the compiler need to reference items in the files?)
UPDATE (16/05/2010):
I posted a similar question with a little more detail for question 2 on Experts-Exchange. I don't want to post all that info here as it just will be too messy but it explains question 2 in greater detail.
For your first question, you want to use svn externals. More details can be found here: http://svnbook.red-bean.com/en/1.0/ch07s03.html
For your second question, you need to create a seperate assembly and the easiest way is to create a new project within your solution. You can't have a single project emit 2 dll's (that I know of)
For your first question:
If the base project is a library then there is nothing stopping you from creating the following directory structure on your SVN:
Base project
Cool project nr 1
Cool project nr 2
All projects built on the Base project will include a relative reference and then everybody can checkout his Cool project X and the Base project and work on them. Checking-in changes for Base project will allow everybody else to see them by updating their Base project image. Advantage: only one SVN trunk required.
For your second question :
I tried my best, but I can't understand what you're asking :).

Categories