简体   繁体   English

解决Visual Studio依赖项

[英]Resolving Visual Studio dependencies

I am parsing the project.assets.json file in a C# project to retrieve the dependencies for a project (I'm doing this as part of a project which is extracting documentation information from the project files). 我正在解析C#项目中的project.assets.json文件,以检索项目的依赖项(我将其作为从项目文件中提取文档信息的项目的一部分来进行)。

I haven't been able to find much documentation for project.assets.json online. 我一直无法在线找到很多project.assets.json文档。 It appears to have a number of sections. 它似乎包含许多部分。

Here's an extract: 这是摘录:

{
    "version": 3,
    "targets": {
        "Microsoft.IdentityModel.JsonWebTokens/5.3.0": {
            "type": "package",
            "dependencies": {
                "Microsoft.IdentityModel.Tokens": "5.3.0",
                "Newtonsoft.Json": "10.0.1"
            },
            "compile": {
                "lib/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.dll": {}
            },
            "runtime": {
                "lib/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.dll": {}
            }
        },
    },
    "libraries": {
        "Microsoft.IdentityModel.JsonWebTokens/5.3.0": {
            "sha512": "GmiwCJPEe+V8+2GO3kD8K0IeqNHlTL0xZcHePIjyJveRn7OderxdT32aCZeJZEvz5w2Jlyag3zdyu1zkdTJo2A==",
            "type": "package",
            "path": "microsoft.identitymodel.jsonwebtokens/5.3.0",
            "files": [
                ".nupkg.metadata",
                ".signature.p7s",
                "lib/net45/Microsoft.IdentityModel.JsonWebTokens.dll",
                "lib/net45/Microsoft.IdentityModel.JsonWebTokens.pdb",
                "lib/net45/Microsoft.IdentityModel.JsonWebTokens.xml",
                "lib/net451/Microsoft.IdentityModel.JsonWebTokens.dll",
                "lib/net451/Microsoft.IdentityModel.JsonWebTokens.pdb",
                "lib/net451/Microsoft.IdentityModel.JsonWebTokens.xml",
                "lib/net461/Microsoft.IdentityModel.JsonWebTokens.dll",
                "lib/net461/Microsoft.IdentityModel.JsonWebTokens.pdb",
                "lib/net461/Microsoft.IdentityModel.JsonWebTokens.xml",
               "lib/netstandard1.4/Microsoft.IdentityModel.JsonWebTokens.dll",
               "lib/netstandard1.4/Microsoft.IdentityModel.JsonWebTokens.pdb",
               "lib/netstandard1.4/Microsoft.IdentityModel.JsonWebTokens.xml",
              "lib/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.dll",
               "lib/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.pdb",
              "lib/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.xml",
                 "microsoft.identitymodel.jsonwebtokens.5.3.0.nupkg.sha512",
                 "microsoft.identitymodel.jsonwebtokens.nuspec"
            ]
        },
    }
}

Conceptually, my parser looks at the targets section and extracts the path to the DLL that gets referenced by the project. 从概念上讲,我的解析器查看targets部分并提取到项目引用的DLL的路径。 For packages, that path is relative to the local nuget package repository (typically C:\\Users\\<username>\\.nuget\\packages ). 对于软件包,该路径相对于本地nuget软件包存储库(通常为C:\\Users\\<username>\\.nuget\\packages )。

But I've run into some situations -- and the extract is one of them -- where the specified DLL ( Microsoft.IdentityModel.JsonWebTokens/5.3.0/lib/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.dll ) doesn't exist in the local nuget repository. 但是我遇到了某些情况-摘录就是其中一种-指定的DLL( Microsoft.IdentityModel.JsonWebTokens/5.3.0/lib/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.dll )不存在。存在于本地nuget存储库中。 In fact, the libraries section shows a repository path ( Microsoft.IdentityModel.JsonWebTokens/5.3.0 ) which doesn't exist in the repository folder (there's not even a Microsoft.IdentityModel.JsonWebTokens folder). 实际上,库部分显示了存储库路径( Microsoft.IdentityModel.JsonWebTokens/5.3.0 ),该路径在存储库文件夹(甚至没有Microsoft.IdentityModel.JsonWebTokens文件夹)中都不存在。

Yet the project with the "broken" reference builds without any errors, and functions properly. 但是,带有“残破”参考的项目可以正确构建,并且没有任何错误。

I'd appreciate any insight others might have on how these "broken" repository paths should be resolved. 我希望别人对如何解决这些“损坏的”存储库路径有任何见解。 If anyone knows of online documentation for project.assets.json that'd be great, too. 如果有人知道project.assets.json的在线文档,那也很好。

Look for the packageFolders section of the project.assets.json file. 查找project.assets.json文件的packageFolders部分。 This is what I have: 这就是我所拥有的:

  "packageFolders": {
    "C:\\Users\\zivkan\\.nuget\\packages\\": {},
    "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
  },

Microsoft.IdentityModel.JsonWebTokens sounds a lot like something that would be used by ASP.NET Core, and therefore the .NET Core SDK NuGetFallbackFolder sounds like a very likely place for it to be. Microsoft.IdentityModel.JsonWebTokens听起来很像ASP.NET Core会使用的东西,因此.NET Core SDK NuGetFallbackFolder听起来很像。

By using the package folders listed in the json file, your program will also be more robust if used on a project that redirects its global packages folder away from the default user profile location. 通过使用json文件中列出的软件包文件夹,如果在将其全局软件包文件夹重定向到默认用户配置文件位置之外的项目上使用,您的程序也将更加强大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM