0

I'm fairly new to using EnvDTE, but I've managed to get it to generate a project using a copy of the Visual Studio-included csConsoleApplication template*. Problem is, I need it to be a net6.0 app, not .NETFramework v4.0, which is what's being generated. I don't know how to change this. It could very well be because the project containing the EnvDTE code to generate this project is a Framework one.

*As I'm using a copy of the template (there are reasons for this which are irrelevant here), if I can edit the .csproj or .vstemplate files (or any of the other template files) to accomplish my goal, that would be fine. Otherwise, there must be a way to do it in the DTE code.

Speaking of which, here's the generation code in case it becomes relevant:

// ... Code to get the DTE instance

dte.Solution.Create(solutionDirectory, currentProject.CodeSafeName);
Solution solution = dte.Solution;

// Don't worry, this won't remain a hard-coded path!
solution.AddFromTemplate(@"C:\Users\Logix\Desktop\TEMPLATE\csConsoleApplication.vstemplate", $@"{solutionDirectory}\{currentProject.CodeSafeName}", currentProject.CodeSafeName, true);

// ... Code to add DLL references

dte.ExecuteCommand("File.SaveAll");
dte.Solution.Close();
dte.Quit();

The template was copied from:

C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\ProjectTemplates\CSharp\Windows\1033\ConsoleApplication

though of course if you need to take a look at those files, you may have to change this path to match your VS version.

Thanks in advance.

Logix
  • 530
  • 6
  • 15
  • Wrong template, the .NET Core templates are stored in c:\program files\dotnet\templates. If you copy the .nupkg file and rename it to .zip then you can browse its content. Or create your own with Project > Export Template. – Hans Passant Nov 15 '21 at 17:56
  • Thank you. Strange that they've two separate locations for the templates. I'm not sure exactly how those template files are missing the .vstemplate file, but I was able to extract the .csproj contents into the template I was using before, which seems to work. Only issue is that it complains about duplicate contents when I include Program.cs in the .csproj ItemGroups, yet I need to for the file to even be copied. This also prevents the project from building. However, I can copy the file manually and the project builds and runs, but this is less than ideal. – Logix Nov 16 '21 at 00:49

0 Answers0