我正在尝试创建一个简单的dotnet new
包含我的团队使用的“默认”.editorconfig 和 .gitconfig 的模板。
不幸的是,.files 不会被包含在dotnet pack
.
这是我的 .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 将被忽略。
有人有这方面的经验吗?
有多种解决方案,最简单的就是添加无默认排除 https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-pack#options(“防止默认排除 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"
}
}
]
}
]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)