8

快速解决编译报错 "未知的生成错误“已添加了具有相同键的项"

 1 year ago
source link: http://blog.devwiki.net/2022/04/22/dotnet-unkown-error.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

快速解决编译报错 "未知的生成错误“已添加了具有相同键的项"

在项目合并代码时出现以下问题:

Microsoft.WinFx.targets(712, 5): [RG1000] 未知的生成错误“已添加了具有相同键的项。”

202204221433750.png

很明显错误的原因就是某个地方出现了相同的键值

当你双击错误时会打开一个 NET framework 的错误, 但是不会提示具体错误在哪.

<ResourcesGenerator
    ResourceFiles="@(MainEmbeddedFiles)"
    OutputPath="$(IntermediateOutputPath)"
    OutputResourcesFile="$(IntermediateOutputPath)$(_ResourceNameInMainAssembly)"
    Condition="'@(MainEmbeddedFiles)' != ''">

    <!-- Put the generated files in item FileWrites so that they can be cleaned up appropriately in a next Rebuild -->
    <Output ItemName="FileWrites" TaskParameter="OutputResourcesFile" />
</ResourcesGenerator>

如果项目比较大, 包含较多的控件, Page, Window, 就很难去排查到底是哪个出现此问题.

如果你去百度或者Google 搜索发现网上确实很多人出现, 但是都特定的项目出现给出了特定的文件,无法类比去排查.

如何快速定位此问题呢?

使用命令行编译, 来查看具体报错, 编译命令如下:

MSBuild.exe xxx.sln /filelogger /fileLoggerParameters:Verbosity=diag

等待编译结果:

  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(712,5): error RG1000: 未知的生成错误“已添加了具有相同键的项。” [D:\Code\xylink\Windows\custom\private_new\xxx\xxx\xxx.csproj]

可以看出是某个项目的工程文件出现相同键值的问题. 这样就可以定位具体的位置了.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK