locked
.Net Standard custom template does not load C# files RRS feed

  • Question

  • Hi

    If I do this:  New Project ... -> (.Net Standard) Class Library then Project -> Export Template... I get a new custom template that appears in Add -> New Project.  However the included Class1.cs file does not appear in the new project created from the custom template. Specifically it does not appear in the Solution Explorer tree and is not copied into the file system. The csproj file is there and appears normally in the Solution explorer but the project is missing the C# file. 

    In the .zip file in My Exported Templates I see that the file is referenced normally:

    <TemplateContent>
        <Project TargetFileName="ClassLibrary1.csproj" File="ClassLibrary1.csproj" ReplaceParameters="true">
          <ProjectItem ReplaceParameters="true" TargetFileName="Class1.cs">Class1.cs</ProjectItem>
        </Project>
     </TemplateContent>

    Also the Class1.cs file is there in the zip.

    Any ideas how I create a custom .Net Standard project?

    Monday, November 13, 2017 7:11 AM

All replies

  • Hi CarltonInFarEast,

    According to your description, i create demo and reproduce your issue on my side, it seems that project template does not support .net standard project template, I would suggest that you could post a feedback on the following link. 

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 17, 2017 8:47 AM
  • Hi CarltonInFarEast,

    I found a solution for this: 

    In my project I need to add App.xaml.cs, App.xaml, MainPage.xaml.cs and MainPage.xaml to project. So I keep .vstemplate file content and in .Net Standard project I add follow code:

      <ItemGroup>
        <Compile Include="App.xaml.cs">
          <DependentUpon>App.xaml</DependentUpon>
        </Compile>
        <Compile Include="MainPage.xaml.cs">
          <DependentUpon>MainPage.xaml</DependentUpon>
        </Compile>
        <EmbeddedResource Include="MainPage.xaml">
          <SubType>Designer</SubType>
          <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
        </EmbeddedResource>
        <EmbeddedResource Include="App.xaml">
          <SubType>Designer</SubType>
          <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
        </EmbeddedResource> 
      </ItemGroup>

    Than I create a wizard for this project template in ProjectFinishedGenerating add this code:

                string projectPath = project.FullName;
                XmlDocument doc = new XmlDocument();
                doc.Load(projectPath);
                XmlNodeList children = doc.ChildNodes[1].ChildNodes;
                foreach(XmlNode child in children)
                {
                    if (child.FirstChild.Name == "Compile")
                        child.RemoveAll();
                }
                doc.Save(projectPath);

    Best wishes,
    Lee

    Friday, December 1, 2017 12:30 AM
  • The issue is related to the missing CreateInPlace element in the .vstemplate file. Refer to  http://irisclasson.com/2017/06/14/visual-studio-2017-templates-and-the-missing-content/

    When I added the missing element my template created the missing files in the expected manner.

    An issue has been logged for this. See  https://github.com/dotnet/standard/issues/605


    • Edited by WernerVN Friday, January 26, 2018 7:24 AM More info
    • Proposed as answer by Li Jun Jie Tuesday, February 6, 2018 1:29 AM
    Friday, January 26, 2018 7:23 AM