dotnet / templating

This repo contains the Template Engine which is used by dotnet new
https://docs.microsoft.com/dotnet/
MIT License
1.59k stars 365 forks source link

`.gitignore` file is not in the generated directory #8198

Closed eatenupme closed 2 weeks ago

eatenupme commented 2 weeks ago

Product

dotnet CLI (dotnet new)

Describe The Bug

When I create a custom project template, I need to add a .gitignore template to it. I have written the .gitignore file, but it does not appear in the generated files. I did not find any description of the .gitignore rules in the documentation.

To Reproduce

Steps:

  1. vi template.csproj

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
          <PackageType>Template</PackageType>
          <PackageVersion>0.0.0</PackageVersion>
          <PackageId>xxx.Templates</PackageId>
          <Title>xxx</Title>
          <Authors>xxxx</Authors>
          <Description>xxxx</Description>
          <PackageTags>dotnet-new;templates;contoso</PackageTags>
          <TargetFramework>net8.0</TargetFramework>
    
          <IncludeContentInPack>true</IncludeContentInPack>
          <IncludeBuildOutput>false</IncludeBuildOutput>
          <ContentTargetFolders>content</ContentTargetFolders>
      </PropertyGroup>
    
      <ItemGroup>
          <Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />
          <Compile Remove="**\*" />
      </ItemGroup>
    </Project>
  2. vi templates/.template.config/template.json
    {
      "$schema": "http://json.schemastore.org/template",
      "author": "xxx",
      "classifications": [
          "xxx"
      ],
      "tags": {
          "language": "C#",
          "type": "project"
      },
      "preferNameDirectory": true,
      "identity": "xxx",
      "name": "xxx",
      "shortName": "xxxx"
    }
  3. vi templates/.gitignore
    ##
    ## Visual Studio Code
    ##
    .vscode/*
  4. dotnet pack & dotnet new install .
  5. dotnet new xxx

dotnet Info

output .NET SDK: Version: 8.0.105 Commit: eae90abaaf Workload version: 8.0.100-manifests.796a77f8 Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: ubuntu.22.04-x64 Base Path: /usr/lib/dotnet/sdk/8.0.105/ .NET workloads installed: Workload version: 8.0.100-manifests.796a77f8 There are no installed workloads to display. Host: Version: 8.0.5 Architecture: x64 Commit: 087e15321b .NET SDKs installed: 8.0.105 [/usr/lib/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 8.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download

Visual Studio Version

No response

Additional context

No response

sayedihashimi commented 2 weeks ago

Files that start with a . are excluded by default when you Pack the project. You can add the property NoDefaultExcludes to prevent that https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-pack#options.

eatenupme commented 1 week ago

Because I'm using the .NET CLI instead of NuGet, I haven't found an option to disable file exclusion. I used the renamefile to solve this issue, and it works for me.