I'm currently working on an ASP.NET Core Web API. One of my scenarios looks like this: the user selects a certain project type/language. Lets say the user selects Python or C#, meaning the user wants to create a Python or C# project template. Is it possible/is there an easy way to create such a project template within the code or would I have to create all files manually in the code? This is actually simply simulating the scenario when a user wants to create a new project in Visual Studio where he selects a template from the create a new project menu, its just that I want to do this with my own service.
For .NET: I would make use of the dotnet new cli tool, and use the ProcessStartInfo together with the Process.Start.
For Python, I would do the same, but require the intallation of pyscaffold.
You can use an embedded resource which is e.g. a ZIP file that contains all the files you need to make a project. You can then extract the ZIP file in your code. That way you can simply update the ZIP file in case you want to add something or update to a newer version of Visual Studio.
Related
Like a lot of developers, I often create new projects with the same features (Authentication, IoC, tests etc..).
What I want to do?
I would like to be able to create a new project based on a custom template code project.
What kind of project?
Currently I'm creating a lot of new in ASP.NET Core MVC projects.
My goal is to generate those new project from a specific template (with some configuration options like the project name).
It's possible in the JavaScript world (with some command lines like expo init my-react-native-project). So is it possible to do it for ASP.NET Core MVC projects?
I hope what I want to do is correctly explained :)
Thank you very much for your help.
You can create a custom template from an existing project by adding a .template.configtemplate.json file
Essentially, you can setup the project to have all of the common functionality you required i.e. Authentication, test, IOC and re-use this in a new project.
Have a look at this post for futher details:
https://devblogs.microsoft.com/dotnet/how-to-create-your-own-templates-for-dotnet-new/
taken from https://learn.microsoft.com/en-us/visualstudio/ide/how-to-create-project-templates?view=vs-2019
This topic shows you how to create a template using the Export Template Wizard, which packages your template in a .zip file.
Use the Export Template Wizard
Create a project.
Note
Use only valid identifier characters when naming a project that will be the source for a template. Otherwise, compilation errors can occur in projects that are created from the template. For more information about valid identifier characters, see Declared element names (Visual Basic) or Identifiers (C++). Alternatively, you can use Template parameters to use "safe" names for classes and namespaces.
Edit the project until it is ready to be exported as a template. For example, you might want to edit code files to indicate where parameter replacement should take place. See How to: Substitute parameters in a template.
On the Project menu, choose Export Template.
The Export Template Wizard opens.
On the Choose Template Type page, select Project Template. Select the project you want to export to a template, and then choose Next.
On the Select Template Options page, enter a name and optional description, icon, and preview image for your template. These items will appear in the dialog box where you create a new project. Choose Finish.
The project is exported into a .zip file and placed in the specified output location, and, if selected, imported into Visual Studio.
To find your template in the dialog box where you create a new project, search for it by name or scroll through the list. (Filtering based on language or project type is not currently possible for user templates.)
Other ways to create project templates
You can create project templates manually by gathering the files that constitute the project into a folder and creating a .vstemplate XML file with the appropriate metadata. For more information, see How to: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-manually-create-web-templates?view=vs-2019
If you have the Visual Studio SDK installed, you can wrap the finished template in a VSIX file for deployment by using the VSIX Project template. For more information, see https://learn.microsoft.com/en-us/visualstudio/extensibility/getting-started-with-the-vsix-project-template?view=vs-2019.
I have a project in c# which is represent a Ground Station for Aircraft.
I need functionality that when I click on save test, then there is a new project same as the Ground station will be created.
simply just like the visual studio project there is a button to create new project, which is same as visual project.
in other word, I need to create new project from same project with customized configuration.
How to do that?
Do you mean how to create an exact copy of the project you're currently working on?
If so, I'm not sure there's an automated way to accomplish this, but you can just go into Documents\Visual Studio %YourYear%\Projects\%YourProject%, where you replace both of the %-delimited values with your local values. Then, just copy your entire project folder, give it a new name, and open the solution therein. You'll be able to edit it as you see fit without changing the original version.
However, I think you'd be better off using some sort of version control system, like Git or Subversion. With either of these, you can create branches off your master version. You can effect whatever changes you like with these branches without affecting any changes to the original master. If you decide the changes you've made on any branch are worth keeping, you can merge some or all of them with the master and create a new master version.
I am currently trying to add a VB file inside a C# project, but I am only able to add C# files. Is there a way for me to be able to add more language templates like what is shown below?
This picture below is an example of what I have been able to do in an old project which is to be able to add both VB and C# files into one project.
Update: I am redeveloping an ASP.NET 2.0 site to the newest version with the new bootstrap framework. I didn't realize the old project was using mostly VB until I started the redevelopment in C#. I noticed that the old project is also using some C#. I am trying to see if I can have those two languages inside a new ASP.NET project or not by adding VB files. If not, I'll just make a VB project and convert all of the C# code to it.
When you open the "Add new file" dialog inside a project, it is filtered by the current project type you're working on. E.g. you cannot add a *.vb file to a C# project type, without hacking it somehow.
The GUID within the *.csproj file defines the current project type. This site contains a set of known GUIDs, it is somewhat outdated since it's from 2008.
As I said in a comment, the reason you have been able to mix-in both VB and C# code within the web project, is by using CodeFile attribute, rather than the CodeBehind attribute. The latter will compile all the source files within the project into an assembly with the same name. This will be the file you are uplading to your webserver along with the .aspx files.
Sample file structure:
bin/MyApp.MyProject.dll
Index.aspx
The CodeFile variant, which compiles the source on the fly will need all the files in the same directory, or in the directory specified within the attribute, for this example it will reside within the same directory. This will also allow you to change the code at the web server, and not having to download the code to your development environment. (This is NOT recommended, as you wave goodbye to any version control and other useful tools.)
Sample file structure:
Index.aspx
Index.aspx.cs
My advice would be to decide whether or not to continue developing in VB, or switch to C#. Containing your codebase to one language is preferrable. And if you decide to refactor the whole solution, why not give ASP.NET MVC a go? :-)
Actually there used to be, not sure if it's still available, to put a VB file in a C# project. You would have needed to add a text file type but name it with a .vb extension. Then place it in a folder. Then in the app or web config, you needed to add some config to tell the runtime where to find the vb files and to use VB compiler to compile the code.
It worked but was clunky and not recommended. Again, not sure if it's available anymore.
Personally, if you have VB code, use a vb2cs converter like this one to begin converting it over. They are not perfect but it's at least a good start in most cases.
I found something related here but did not give me a good start
Since recently I do a lot of webPart development I want to automate the none-code part of the process, I want to develop a small console app that creates SharePoint solution as the pic, i'll use it as a template for the upcoming webParts
assume the webpart name is a var
string webPartName = "usefulLinks";
Create Empty SharePoint Project
Add Visual WebPart webPartName
Create Classes Folder WebPartName
Create an empty class inside the folder
add the Layouts mapped folder
add css and img folders to the layouts folder
Change part of the .webpart content to custom values
Same to the Elements.xml file
add the Resources mapped folder and add two resources files for Arabic and English
and finally change the feature name to be like webPartName + Feature
any good starting points? or online resources
thank you.
What you are really describing is a custom SharePoint Solution Project, not a Visual Studio solution.
Project templates provide the files that are required for a particular project type, include standard assembly references, and set default project properties and compiler options.
This section in MSDN covers how to create project templates for Visual Studio. In particular, it sounds like the best option for you is the "Export Template Wizard", which will create a template based on an existing project you have created.
I'm currently working on an application that will generate actual .cs and .xaml code files and add them to a project. I've managed to do this by manually editing an existing .csproj file and thats working well.
However I would like to be able to create the project files from my application as well, to cut out the extra step of creating the project first then running the application after.
Does anyone know how to create a C# project (class library, or WPF Application) from an application? I've looked into DTE, but I've hit a wall
I can't give a complete answer, but maybe I can point you in the right direction.
One avenue to explore in your own searching is MSBuild. C# and VB.net project files follow the msbuild format, and so the first step in building a valid project file is building a valid msbuild file.
Also, it sounds like you're doing something a little different, but have you looked at the T4 system for code generation?