[英]Create Visual Studio Custom Template containing .cshtml files and pack in Nuget Package
我正在嘗試按照此處提到的步驟使用 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="xxxxx\xxx.cshtml" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
</metadata>
<files>
<file src="xxxxx\xxx.cshtml" target="ContentFiles\any" />
<file src="xxxxx\xxx.cshtml" target="Content" />
</files>
</package>
3)在輸入nuget pack xxx.csproj
生成nuget包之前,你應該先重建你的項目。
希望能幫到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.