创建包含 .cshtml 文件的 Visual Studio 自定义模板,并打包在 Nuget 包中



我正在尝试按照此处提到的步骤使用Visual Studio 2019在.NET Core 3.1中创建自定义模板。我已经在链接中提到的.csproj文件中进行了更改。当我通过直接引用项目文件夹安装模板并创建一个项目时,一切都运行良好,并且还创建了 cshtml 文件。

但是当我尝试使用 nuget 包 .cshtml 安装模板时,项目输出中不包含文件。谁能告诉我如何在Nuget包中包含.cshtml文件。

我正在使用以下命令

创建 nuget 包 -->dotnet pack --output nupkgs

使用 nuget 安装自定义模板 -->dotnet new -i <Path To Nuget Package>testinmem.1.0.0.nupkg

要创建项目 -->dotnet new testis4inmem -n qwerty --force

但是

当我尝试使用 nuget 包 .cshtml 安装模板时 文件不包括在项目输出中。谁能告诉我如何 在 Nuget 包中包含 .cshtml 文件。

我认为您可以将 nuget.exe cli 与 nuspec 文件一起使用。

1(首先确保已按照本指南配置环境,然后可以在 CMD 中调用 nuget.exe。

使用CMD进入项目文件夹(存在哪个xxx.csproj文件(

2(键入nuget spec以生成 xxx.nuspec 文件并像这样修改:

<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>1</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>Tag1 Tag2</tags>
<contentFiles>
<files include="xxxxxxxx.cshtml" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
</metadata>
<files>
<file src="xxxxxxxx.cshtml" target="ContentFilesany" />
<file src="xxxxxxxx.cshtml" target="Content" />
</files>
</package>

3(在键入nuget pack xxx.csproj以生成 nuget 包之前,应先重新生成项目。

希望它能帮助你。

最新更新