Igavshne
Igavshne

Reputation: 697

Delete Class1.cs from project programmatically when using template to create solution in VS 2015.

I create a solution programmatically using the standard Class Library template. Some of the important parts are:

 Solution2 soln = (Solution2)visualStudioInstance.Solution;
 csTemplatePath = soln.GetProjectTemplate("Windows Root\\Windows\\1033\\ClassLibrary\\csClassLibrary.vstemplate", "CSharp");

 soln.AddFromTemplate(csTemplatePath, csPrjPath, "MyProject", false);

Then I add references and files etc. However, a Class1.cs is generated, but I don't want that in my solution. How can I delete it programmatically?

I assume I have to loop through something and search for an item with the name "Class1.cs", but I'm not sure what object would contain a list of all the files in my project.

Upvotes: 1

Views: 557

Answers (1)

Sabrina_cs
Sabrina_cs

Reputation: 421

To create personalized projects you can create a copy of the class template without the Class1.cs file and then you can use the new template for your solution.

To do so just create a new project from the class library delete the class1.cs file and from visual studio on the File Menu choose "Export Template" the wizard creates the new template that you then can use.

Pay attention only to one little problem: usually the new project if you choose to install it in the User template folder is saved in:

C:\Users\UserName\Documents\Visual Studio 2015\Templates\ProjectTemplates\YournewTemplatename.zip

The name of the visual studio folder depends on your visual studio version, unfortunately the template in that folder is not visible from the Add new project so you need to move it to:

C:\Users\UserName\Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#\YourNewTemplate.zip

And it becomes visible in this case under the Visual C# projects, if you prefer to install the template as a default template you must do the following:

Copy your projecttemplates to

"%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE\ProjectTemplates\Visual C#\"

Then run the template installation utility

"%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE\devenv" /installvstemplates

Also in this case the Visual studio folder depends on the version you are using so check on your disk which is the one you are using.

Upvotes: 1

Related Questions