Powershell dte 创建目标平台项目

Powershell dte create project of targeting platform

PM> $dte.Solution.Create("C:\Projects\test\", "test.sln")
PM> $t = $dte.Solution.GetProjectTemplate("ConsoleApplication.zip", "CSharp" )
PM> $dte.Solution.AddFromTemplate($t, "C:\Projects\test\proj\", "New CSharp Console Project", $false)

我正在使用 VS 2017。这将创建一个解决方案和一个项目。该项目以 .NET Core 为目标。如何更改此行:

PM> $t = $dte.Solution.GetProjectTemplate("ConsoleApplication.zip", "CSharp" )

为了能够针对以前的 .NET 版本 - 4.6/4.7

是否有查看可用项目模板的命令?

The VS2017 SDK documentation 建议您可以传入一个 FrameworkVersion 参数作为模板名称的一部分:

If a template has a RequiredFrameworkVersion element higher than 4.0, you should provide the version in the call so that the search for the template will find a match. For example, instead of calling GetProjectTemplate("Extensibility33\VSIXProject.zip", "CSharp"); call GetProjectTemplate("Extensibility33\VSIXProject.zip|FrameworkVersion=4.5", "CSharp");.

所以我希望它能按您的需要工作:

$dte.Solution.GetProjectTemplate("ConsoleApplication.zip|FrameworkVersion=4.6", "CSharp")