Visual Studio Project Template Support for new csproj format

Viewed 793

I'm working on creating some templates in Visual Studio 2019, to use the new .csproj format (based on the SDK property), and I'm running into an issue.

Normally, if you want to include a file in the template, you add it in the .vstemplate:

  <TemplateContent>
    <Project File="ProjectTemplate.csproj" ReplaceParameters="true">
      <ProjectItem ReplaceParameters="true" TargetFileName="$classprefix$Config.cs">ProjectTemplateConfig.cs</ProjectItem>
    </Project>
  </TemplateContent>

and in the .csproj:

<ItemGroup>
    <Compile Include="$classprefix$Config.cs" />
</ItemGroup>

And everything just works as it should.

However, I'm trying to use the new format where you do not include the individual files in the .csproj, it automatically picks up all files in your project folder.

But when I remove the <Compile> tag from the csproj, the template no longer copies the file.

I'm even using an IWizard, and I can see the call Visual Studio makes to IWizard.ShouldAddProjectItem(string) to which I return true, however it does not add it.

The need is more extreme when working with WPF, where by if you add a second <Page> tag, the compiler will actually throw an error.

Do Visual Studio templates support the new .csproj format? And if so, how can I have it copy files regardless of their presence in the .csproj file?

1 Answers

Do Visual Studio templates support the new .csproj format? And if so, how can I have it copy files regardless of their presence in the .csproj file?

In fact, VS does not support creating project template for the new sdk format projects at present.

Actually, VS2019 only has the Net Framework project template which works for creating old sdk format projects. And if you simply modify the xxxx.csproj file in such project into the new sdk format like what you did in your situation, but the framework of the template project itself is still net framework(simply migrating the old sdk format to the new sdk format still has various compatibility issues), as a result, the final template still works for net framework projects rather than net core/net standard projects.

As a suggestion,

I suggest you could create a new sdk format project, make some requirements changes as you want and then use VS UI option Export Project Template to export such new sdk format projects and I think this will works well.

In addition, if you still want to create the project template which works for new sdk format projects, we recommend you could post a feature request in our User Voice forum(DC)----suggest a feature to share your idea and the team will seriously consider your idea and give you a satisfactory reply.

Related