Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Project Template Support for new csproj format

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?

like image 430
Adam Schiavone Avatar asked Oct 29 '25 16:10

Adam Schiavone


1 Answers

I got this working in Visual Studio 2022.

I added <CreateInPlace>true</CreateInPlace> to the vstemplate file and then all files are copied even when setting <EnableDefaultCompileItems>true</EnableDefaultCompileItems> (which is default to true)

like image 64
testalino Avatar answered Oct 31 '25 07:10

testalino