Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.gitignore file is not in the generated directory #8198

Closed
eatenupme opened this issue Jul 5, 2024 · 2 comments
Closed

.gitignore file is not in the generated directory #8198

eatenupme opened this issue Jul 5, 2024 · 2 comments

Comments

@eatenupme
Copy link

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>
  1. 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"
}
  1. vi templates/.gitignore
##
## Visual Studio Code
##
.vscode/*
  1. dotnet pack & dotnet new install .
  2. 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
Copy link
Member

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants