简体   繁体   English

如何包含 class 库引用的 nuget 包

[英]How to include nuget packages referenced by a class library

I have a Visual Studio web app with 2 projects in the solution: the main C# app and another C# class library I wrote.我有一个 Visual Studio web 应用程序,在解决方案中有 2 个项目:主 C# 应用程序和另一个 C# ZA2F2IA1ED4F8EBC2ABCB4DC2 库写了。 The class library references some nuget packages. class 库引用了一些 nuget 包。

When I build & run my solution I get a reference problem because the main app doesn't have the nuget packages.当我构建和运行我的解决方案时,我遇到了一个参考问题,因为主应用程序没有 nuget 包。 The only way I can get it to run is to add the nuget packages again to the main app, even though it doesn't actually use them.我可以让它运行的唯一方法是将 nuget 包再次添加到主应用程序,即使它实际上并没有使用它们。

Is there a way to get VS to automatically include the relevant packages in the final build?有没有办法让 VS 在最终构建中自动包含相关包?

在此处输入图像描述

If your class library project is net standard and main project is non-sdk net framework project, you should add this under the csproj file of the main app:如果您的 class 库项目是net standard并且主项目是非 sdk 网络框架项目,则应在主应用程序的 csproj 文件下添加:

<PropertyGroup>
        
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
    
</PropertyGroup>

This issue might be the same as yours. 这个问题可能和你的一样。

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

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