The best way to extend fsproj template - f#

I want to create custom project template based on F# project (fsproj). Requirements:
Custom project properties. So, property page extension required.
Custom file type support. Custom project item template should be created.
Custom build action for custom file type. Corresponded MsBuild task will be created.
As I know, some parts of C# project ecosystem are in SDK, so can be inherited (it looks useful for deep customization), but F# is not. So my question is what the best way for deep customization of F# project template?

Related

Custom Build Action similar to AndroidResource

I am trying to organise an Android project's layout files. Having already worked with MVC, I tried to apply that architectural pattern to the Android project.
Suppose I have a folder structure in my Android project:
Areas > SomeAreaName > Views > details_layout.xml
Setting the Build Action on "details_layout.xml" to AndroidResource results in an "invalid file path" error which is understandable as Android does not allow for files in different locations other than the predefined "res" folder and subfolders.
Is it possible to create a custom Build Action (e.g. AndroidResourceMvc) that can utilise the existing AndroidResource Build Action and with the added ability to appropriately map layout files? If so, how would I go about this?
I've looked at the AndroidResource file and with it being internal and private I don't really have access to it. Neither am I able to just use the raw source code as it imports some namespaces that I also do not have access to (or I just can't seem to find them if they're publicly available).
I'm using Visual Studio 2019 and a Xamarin Android C# project.

How do I convert a specific controller to a package to include in other projects?

VS2013, MVC5, VB
I am nearing the completion of a small project to manage the roles tables in a standard MVC5 application. The code is pretty much encapsulated. What are my options for using this 'package' in other projects?
Can I compile it into something? I know this type of action is possible, I'm just not familiar with the options available to me or the steps to do this. Links to sites that have tutorials are fine. Is creating a Nu Get package the only way to go, or is that even in the ballpark of what I'm asking. I say Nu Get, but I don't mean for public consumption, only for my consumption.
Will the finished 'whatever' include it's controller class, view models and views? Will I be able to easily manage updates? etc.
Creating a Nuget package is one way. I have created a local repository of common utilities for this purpose. But I usually use it just for DLLs. I use Nuget Package Explorer for its ease of use since its just me using the packages most of the time. Not sure its possible to place the files in specific directories.
Files in the content folder are copied to the root of your application when the package is installed. - Nuget
The alternative is to create an item template. I used to use this method for class files I want in my code but I can't see why you couldn't do it for the rest. Works well and isn't too hard to set up. There are dozens if not 100s of tutorials on the subject. Here is one on code project.

Adding another t4 template to Reverse Engineer Code First process

I'm using Entity Framework Power Tools Reverse Engineer Code First to generate my poco classes, mapping files, and context from the database. I would also like for this process to create my base partial Validation classes for each entity. I am fine with writing the t4 template, but is there a way I can shoehorn that into the process when I run the Reverse Engineer Code First process?
I may be misunderstanding your question, but if not, one way to do it is to add the code to Entity.tt and have your class files include both the POCO class and your validation class. It's generated code that you shouldn't have to be referencing much if at all outside of intellisense in the calling code.
Alternatively maybe you could add a new validation class generating .tt file to the ReverseEngineerCodeFirst folder, but I haven't tried it and it wouldn't surprise me if running ReverseEngineer Code First would not actually run it.
I recently customized the Entity Framework PowerTools to produce an interface for the model context. For this purpose, I added an Interface.tt template. You can review my changes at https://entityframework.codeplex.com/SourceControl/network/forks/khawajaumarfarooq/PowerToolEnhancements.
The source code does have to be modified to add extra templates to be processed when reverse engineering POCO classes.
The source code would also have to be modified if you want to generate additional files and have them be included in the project programmatically, as opposed to adding them in yourself after code generation is complete.

Proper method for creating Entity Class files for MVC?

I know that this information is available somewhere but I obviously don't know how to search for it using the right keywords.
I have downloaded the NerdDinner code and also have the e-book. I have followed the example in the book as well though I have not completed it yet. But my question is really very simple.
I want to follow a repository design pattern and I keep seeing "Visual Studio automatically generates .NET classes that represent the models and database relationships defned using the Entity Framework Designer. An ObjectContext class is also generated for each Entity Framework Designer fle added to the solution." in some phrase or another. But when I create an Entity Framework Project a .designer.cs file is created and basically has all the class entities contained in it which confirms the 2nd portion of the statement. However, I don't automagically get separate class files generated for those entities.
How do I get that? I know I could comb through the designer file and gut out the class declarations for each entity and create a separate file for each of them but it seems like a trivial way to do it like that. So what is the right way???
Is there a tool or some documentation that I can refer for the proper way to create separate Entity Class files?
It's been awhile since I last used Entity Framework but:
If you use the designer to create your model you can use partial classes in separate files to extend or build upon.
There is/was an extension project using Visual Studio that will generate POCO classes based on your EF designer model. You can use those as a one off tool and after that continue working with the resulting classes, you may need to continuously fix your mappings after that point though. Not sure if this POCO template is still current, look for Entity Framework and POCO.
MS has been working on better code first support, my preferred way of working. I haven't looked into it yet, I assume it will try to auto-generate mapping and database based on your classes/entity definitions.

Visual Studio: What approach do you use to 'template' plumbing for similar projects?

When building ASP.NET projects there is a certain amount of boilerplate, or plumbing that needs to be done, which is often identical across projects. This is especially the case with MVC and ALT.NET approaches. [I'm thinking of things such as: IoC, ORM, Solution structure (projects), Session Management, User Management, I18n etc.]
I would like to know what approach you find best for 'reusing' this plumbing across projects?
Have a 'master solution' which you duplicate and rename somehow? (I'm using a this to a degree at the moment, but it's fairly messy. Would be interested how people do this 'better')
Mainly rely on Shared Library projects? (I find this appropriate for some things, but too restrictive for things that have to be customised)
Code generation tools, such as T4? (Similar to the approach used by SharpArchitecture - have not tried this myself)
Something else?
Visual Studio supports Custom Templates.
I definitely (mostly!) go for T4 templates in conjunction with a modified version of SubSonic 3. I kind of use the database to model my domain and then use the T4 templates to generate the model and associated controllers and views. It takes about 50-60% of the effort out and keeps a consistency in place.
I then work on overrides (partials) of the classes along with filters and extension methods to 'make the app'. Now that I'm familiar with the environment and what I'm doing, I can have a basic model with good plumbing in place in a very short space of time. More importantly, because I create a set of partial class files, I can regenerate all I want without losing any of my 'custom' coding.
It works for me anyway :)
You could do it the bearded, t-shirted, agile style and create a nice template and put it in sourcecontrol. So when you need a new project, you just checkout the template?
For insanely fast MVC site setup, I use modified T4 templates (created with T4 Editor) and with ALOT of help from Oleg Sych's blogs for page generation (for your typical add/edit/index pages) combined with an awesome implementation of an automated create-update-delete called MVCCrud (if LINQ-to-SQL is your preferred data access method)
Using modified T4 templates and MVCCrud you can create fully functional entities (Create/Edit/List/Delete) with error handling and intuitive error messages in about 4 minutes for each.
I create a new project using the new project wizard so that I get unique project GUIDs assigned. Then I would use "Add Existing Item" to copy items from similar projects if it made sense to do so.
I sometimes use a file diff tool to copy references from one project to another, otherwise I just add the references by hand. A file diff tool can also be used to include similar source files, but the underlying files have to be copied anyway, so I prefer "Add Existing Item".
I've used T4 to generate solution and project files, but that definitely seems like an edge case and not something that would normally be necessary. In that case, I'd probably wrap the T4 in a PowerShell like script to create and populate the rest of the directory structure.
I use "shared libraries" pretty aggressively in general, but not specifically due to this scenario.
In general, I don't find myself reusing plumbing between projects much. It's probably more often that I hack away in one "prototype" project, then abandon it, and rebuild the project from scratch following the above approach and only bring over the "non-hacky" code.
I'm creating a MVC2 application template at http://erictopia.com. It will contain all the basic items I think should be in a MVC project. These include BDD specifications, an ORM (NHibernate and possibly Lightspeed), T4 templates, custom providers, ELMAH support, CSS/Javascript minifier, etc.

Resources