将 Roslyn 代码重构作为 NuGet 包发布 [英] Ship Roslyn code refactoring as NuGet package

查看:48
本文介绍了将 Roslyn 代码重构作为 NuGet 包发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装 .NET Compiler Platform SDK 时,您将获得用于创建带有代码修复的分析器 (NuGet + VSIX)"和代码重构 (VSIX)"的 Visual Studio 模板.

When installing the .NET Compiler Platform SDK you get Visual Studio templates for creating an "Analyzer with Code Fix (NuGet + VSIX)" and a "Code Refactoring (VSIX)".

为什么没有使用 NuGet 进行代码重构的模板(例如代码重构 (NuGet + VSIX)")?
甚至可以从 NuGet 包添加代码重构提供程序(通过手动创建 NuGet 包)?
在每个项目的基础上为一个项目安装代码重构提供程序没有意义吗?

Why isn't there a template for shipping a code refactoring with NuGet (like "Code Refactoring (NuGet + VSIX)")?
Is it even possible to add a code refactoring provider from a NuGet package (by creating the NuGet package manually)?
Doesn't it make sense to install a code refactoring provider on a project per project basis?

我的用例是代码重构,它从无类型数据(如 JSON)中生成 C# 类型.这基本上就是 F# 类型提供程序(尽管它们当然更强大).这意味着用户创建了一个如下所示的类

My use case is a code refactoring that generates a C# type out of untyped data (like JSON). This is basically what F# type providers are (although they are much more powerful of course). This means that the user creates a class like the following

[JsonProvider("http://example.com/data.json")]
public class ExampleData
{
}

并且重构用它从属性中的 url 获取的示例数据中的属性填充它:

and the refactoring fills it with properties from the sample data it fetched from the url in the attribute:

[JsonProvider("http://example.com/data.json")]
public class ExampleData
{
    public string Property1 { get; private set; }
    public int Property2 { get; private set; }

    public void Load(Uri uri) { ... }
    public void FromData(string data) { ... }
    ...
}

我不想创建分析器的原因是用户应该能够决定何时更新 C# 类型.因为我真的不知道 URL 指向的数据何时发生变化.而且我不想用她无法摆脱的波浪线来惹恼用户.

The reason I don't want to create an analyzer is because the user should be able to decide when to update the C# type. Because I don't really know when the data the URL points to is changing. And I don't want to annoy the user with a squiggly line that she can't get rid of.

推荐答案

目前不支持通过 NuGet 分发重构,但我们希望在未来添加.

Distributing refactorings via NuGet is not currently supported, but is something we would like to add in the future.

这篇关于将 Roslyn 代码重构作为 NuGet 包发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆