【问题标题】:Xml Doc comments in c# embedded resources on .NET (Core).NET (Core) 上的 c# 嵌入式资源中的 Xml Doc 注释
【发布时间】:2021-06-21 12:30:57
【问题描述】:

我有一个 c# 项目从 .NET 框架迁移到 .NET Core(然后是 .NET 5)。

我们已经有几年没有碰过我们的.resx 文件了,但是现在我更新了一个.resx 文件,Resources.Designer.cs 文件重新生成了(很好),删除了所有以前的-包含 Xml Doc(不好,产生很大的差异,也会丢失信息)。

如何指示我的 Resx 构建步骤像过去一样保留/生成 XML Doc?

最初这段代码是在 Windows 上使用 Visual Studio 编写和生成的,现在我们在 Mac 上使用 Rider

编辑:看起来它不是特定于 .NET 5,而是 Windows+VS 与 Mac+Rider 配对,因为我团队中的一个 Windows 开发人员在我的更改之上重新生成了这些 cmets。

如何在没有 Visual Studio 的 Mac/Linux 上获得此功能?

旧文件部分:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Resources {
    using System;
    
    
    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    public class Resources {

...

        /// <summary>
        ///   Looks up a localized string similar to About.
        /// </summary>
        public static string About {
            get {
                return ResourceManager.GetString("About", resourceCulture);
            }
        }

新文件部分:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Resources {
    using System;
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
    [System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    public class Resources {

...

        public static string About {
            get {
                return ResourceManager.GetString("About", resourceCulture);
            }
        }

有问题的文件从 12k LOC 下降到 8k LOC,这会丢失很多 cmets,并使处理变得更加困难。

【问题讨论】:

  • @HansPassant 我认为OP意味着自动生成的cmets丢失了,而不是它们最初是手动完成的。
  • @HansPassant 我只担心以前自动生成的 cmets,现在它们不是了。我可以在问题中更改什么以使其更明显吗?

标签: c# .net visual-studio resx xml-documentation


【解决方案1】:

我不知道这是否对您有用,但我的建议是,当出现操作系统/工具问题时,启动 Docker 并从 Windows Docker 映像手动执行 MSBUILD 命令。我建议这样做,因为您的 WinDev 同事正在重新生成丢失的 cmets。

MSBUILD Commands

想到的唯一一个不起作用的问题就像下面链接的那样,他们仍然需要指定配置类型,并且项目(.CSPROJ 文件)被设置为“构建”文档配置。文档生成是“构建”和 Visual Studio“配置”特定的。

例如,如果在启动项目构建时构建了文档,并且将“调试”和“任何 CPU”设置为配置,那么这与您需要在 MSBUILD CLI 中使用必要参数(例如)调用的文档相同

看起来有点像这样(根据粗略的记忆)。

msbuild.exe MyProject.csproj `
/p:Configuration=Debug `
/p:Platform="Any CPU" `
/p:GenerateDocumentation `
/p:DocumentationFile="MyProject.xml"

Stackoverflow - MSBUILD XML Docs

这一切都可以编写脚本,因此它几乎可以启动一个 Docker 映像,POSH 编写构建文档生成脚本,然后将文档复制到本地主机。有点笨重,但你只需要在完成并准备好推上它时再做。

【讨论】:

    猜你喜欢
    • 2016-12-10
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    相关资源
    最近更新 更多