gpt4 book ai didi

templates - 在 dotnet 新模板中包含 "hidden"文件

转载 作者:行者123 更新时间:2023-12-05 09:03:17 24 4
gpt4 key购买 nike

我正在尝试创建一个简单的 dotnet new 模板,其中包含我的团队使用的“默认”.editorconfig 和 .gitconfig。

很遗憾,dotnet pack 期间不会包含 .files。

这是我的 .csproj 的一部分:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageType>Template</PackageType>
<TargetFramework>net6.0</TargetFramework>

<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
</PropertyGroup>

<PropertyGroup>
<Description>dotnet new templates</Description>
<PackageTags>template dotnet console</PackageTags>
<Version>1.0.0</Version>
</PropertyGroup>

<ItemGroup>
<Compile Remove="**\*" />
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**;templates\**\.vs\**" />
<Content Include="templates\SolutionTemplate\.editorconfig;templates\SolutionTemplate\.gitignore" Pack="true" />
</ItemGroup>

</Project>

尽管已明确添加,但 .editorconfig 和 .gitignore 将被忽略。有没有人有这方面的经验?

最佳答案

有多种解决方案,最简单的是添加 NoDefaultExcludes (“防止默认排除 NuGet 包文件以及以点开头的文件和文件夹,例如 .svn 和 .gitignore。”)到您的 csproj,如下所示:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoDefaultExcludes>true</NoDefaultExcludes>
...
</PropertyGroup>
</Project>

使用此选项将包含 .editorconfig 和 .gitignore 文件,但也可能包含其他以点开头的文件或包文件。

我使用了另一个选项来命名模板存储库 editorconfig 和 gitignore 中的文件,并在 .template.config/template.json(在模板安装期间执行)中将文件重命名为 .editorconfig 和 .gitignore,如下所示:

{
...
"sources": [
{
"modifiers": [
{
"rename": {
"editorconfig": ".editorconfig",
"gitignore": ".gitignore"
}
}
]
}
]
}

关于templates - 在 dotnet 新模板中包含 "hidden"文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70095716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com