- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 dotnet core 编写自定义代码生成器,但由于相关文档有限,目前收效甚微。
浏览了一下 CodeGeneration 源代码,了解了如何从命令行触发生成器及其内部工作原理。
由于 dotnet core 中可用的生成器不能满足我的需求,我尝试编写自己的 CodeGenerator,但似乎无法通过“dotnet aspnet-codegenerator”命令调用它。下面是我的自定义代码生成器(目前没有实现 - 我的目标是能够从 dotnet cli 触发它并以异常结束),
namespace TestWebApp.CodeGenerator
{
[Alias("test")]
public class TestCodeGenerator : ICodeGenerator
{
public async Task GenerateCode(TestCodeGeneratorModel model)
{
await Task.CompletedTask;
throw new NotImplementedException();
}
}
public class TestCodeGeneratorModel
{
[Option(Name = "controllerName", ShortName = "name", Description = "Name of the controller")]
public string ControllerName { get; set; }
[Option(Name = "readWriteActions", ShortName = "actions", Description = "Specify this switch to generate Controller with read/write actions when a Model class is not used")]
public bool GenerateReadWriteActions { get; set; }
}
}
下面是我尝试调用代码生成器的方式,
dotnet aspnet-codegenerator -p . TestCodeGenerator TestController -m TestWebApp.Models.TestModel
或
dotnet aspnet-codegenerator -p . test TestController -m TestWebApp.Models.TestModel
不过,这似乎不起作用,并提示无法找到自定义代码生成器。请参阅下面的错误消息,
Finding the generator 'TestCodeGenerator'...
No code generators found with the name 'TestCodeGenerator'
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGeneratorsLocator.GetCodeGenerator(String codeGeneratorName)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:06.23
我缺少什么或者我应该做哪些更改才能让 CogeGenerator 接收我的自定义类(class)?
复制:Github
最佳答案
好的。找出我的代码中缺少的内容。
几乎所有内容都是正确的,除了自定义代码生成器不能与 Web 项目驻留在同一程序集中这一事实外,自定义代码生成器应该作为包引用从 Web 项目中引用(项目引用将不起作用).
以下是自定义代码生成器对 dotnet cli 代码生成器可见的要求,
Microsoft.VisualStudio.Web.CodeGeneration
作为依赖dotnet pack -o ../custompackages
(确保将此位置 (../custompackages) 添加到 nuget.config)
注意:我问题中的代码有一个不接受 Model 参数(-m 开关)并需要 controllerName 参数的模型,因此,要调用您必须使用的代码生成器,
dotnet aspnet-codegenerator -p . test --controllerName TestController
或
dotnet aspnet-codegenerator -p . TestCodeGenerator --controllerName TestController
引用相关讨论here
关于c# - 为 Dotnet Core 编写自定义代码生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41352970/
我在 Ubuntu v16.04 上安装了 dotent core。问题是当我尝试使用 dotnet user-secrets 时它说:未找到匹配命令“dotnet-user-secrets”的可执行
好。这似乎是我看到答案时会面对的问题类型。 所以... 为什么要打扰 dotnet build做之前dotnet publish ? build自动执行 restore .凉爽的。 好像publish
我正在尝试创建一个 dotnet 新模板的 NuGet 包。我创建了一个 nuspec 文件来设置包的详细信息,它位于我的内容文件夹旁边,其中包含我想要打包的所有内容: My.
我正在尝试使用'dotnet dev-certs'工具导出https证书以包含在Docker镜像中。现在我正在使用: dotnet dev-certs https -v -ep $(HOME)\.as
我昨天从 .Net 5 更新到 .Net 6,现在我的项目无法从 dotnet run 开始。然后我得到错误: Building... warn: Microsoft.AspNetCore.Serve
我使用 dockerfile 成功构建,但是当我尝试从构建镜像运行新容器时,出现以下错误: 我必须为解决方案做什么? Error : /bin/sh: 1: [dotnet,: not found d
我有一个引用其他几个项目的 .NET Core 3 项目。我的主根项目有一个 Release-X构建配置,但其他项目只有 Release配置,无匹配 Release-X配置。 当我尝试使用这个发布我的
我的 dotnet new 列表中有许多“孤立的”dotnet 模板。 它们不再存在于我的驱动器上,因为我删除了文件夹,所以我不能 dotnet new --uninstall。 有没有办法从列表中删
编辑: 以下是最初与标题一起发布的前一个问题 xunit show ITestOutputHelper output when run in the console 经过调查(见评论),这个问题仍然非
来自 docs.microsoft.com: dotnet build - Builds a project and all of its dependencies. dotnet run - Run
我有一个 Dotnet 核心项目,我试图在其中安装 Microsoft.EntityFrameworkCore.Tools.Dotnet 以使用迁移。我在 Mac 上,所以我使用 MySql.Data
我已经在这个问题上徘徊了很长一段时间,但仍然没有找到答案,也没有其他帖子处理同样的问题。 我已经发布了一个 .net 5.0 网站,如果我在同一个发布的文件夹中运行 dotnet,一切都会正常运行。在
我正在尝试使用 CLI dotnet 命令复制以下 Azure 管道: - task: DotNetCoreCLI@2 inputs: command: publish publi
假设这个文件夹结构 SampleApp global.json Src Web pro
我正在使用dotnet watch命令来运行asp.net core项目。但是,默认情况下,它选择 Production 作为环境。 我已经尝试了这两个选项: 1) > dotnet watch AS
我正在尝试在 Linux 主机上的官方 Microsoft/dotnet 镜像之外的容器中构建一个 dotnet 项目,因为该镜像与 Windows 和 Linux 都兼容。我只有 linux 主机,
我不是 Linux 用户,所以这可能是一个简单的修复,但我已经尝试了以下方法: 首先我使用命令 curl -sSL https://dot.net/v1/dotnet-install.sh | bas
我在发布配置文件中遇到了 Visual Studio 和 EF 迁移的奇怪情况。鉴于: Visual Studio 2019 v16.4 .NET 核心项目。目标 .NET Core 3.1 EF 3
我已经安装了 .NET Core 1.0.1 以与 VS 2015 Update 3 一起使用,并且以管理员身份运行(在 Windows 8.1 x64 上)。 如果我创建任何 .NET Core 项
我正在尝试为dotnet core 2创建开发Dockerfile。到目前为止,我的工作是: FROM microsoft/aspnetcore-build:2.0 VOLUME /app WORKD
我是一名优秀的程序员,十分优秀!