简体   繁体   English

Visual Studio dotnet核心复制和粘贴参考

[英]Visual Studio dotnet core copy and paste references

I've known about copy/paste references in Visual Studio since 2010/2012. 自2010/2012年以来,我就已经了解Visual Studio中的复制/粘贴引用。 Has this been updated to work with Core 2? 是否已更新此版本以与Core 2配合使用?

Here's the SO Question asking about the old style references (before Core, and before the reboot of csproj format): Is it possible to copy / paste References from one project to another in Visual Studio? 这是SO问题,询问旧样式引用(在Core之前和csproj格式重新启动之前): 是否可以在Visual Studio中将引用从一个项目复制/粘贴到另一个项目?

Maybe now that dotnet add package is available, we don't need copy/paste references in VS? 也许现在可以使用dotnet add package ,我们在VS中不需要复制/粘贴引用了吗?

"Add Google social login" walkthrough for ASP.NET Core 2.0 suggests using the dotnet CLI to add a package reference: ASP.NET Core 2.0的“添加Google社交登录”演练建议使用dotnet CLI添加程序包引用:

  • To install with .NET Core CLI, execute the following in your project directory: 要使用.NET Core CLI进行安装,请在您的项目目录中执行以下操作:

    dotnet add package Microsoft.AspNetCore.Authentication.Google

source: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?tabs=aspnetcore2x 来源: https : //docs.microsoft.com/zh-cn/aspnet/core/security/authentication/social/google-logins?tabs=aspnetcore2x

Writing this answer to my own question so the "just use the CLI" folks have something to upvote. 将这个答案写到我自己的问题上,以便“仅使用CLI”的人就可以提出一些建议。

If you are talking about NuGet package references, don't try to copy the resolved references to dll files manually (the are generated from the obj\\project.assets.json file during the design-time build after loading the project). 如果您正在谈论NuGet包引用,请不要尝试将解析的引用手动复制到dll文件(这些文件是在加载项目后的设计时构建期间从obj\\project.assets.json文件生成的)。

In the new SDK-based project model and the PackageReference way of referencing NuGet packages (also available for "classic" projects), NuGet references automatically flow transitively across package references. 在基于SDK的新项目模型和引用NuGet包的PackageReference方法(也可用于“经典”项目)中,NuGet引用自动在包引用之间传递。 So when your app references a library that uses a NuGet package, you no longer need to install the NuGet package in both the library and the app (and potentially test projects). 因此,当您的应用引用使用NuGet程序包的库时,您不再需要在库和应用程序中都安装NuGet包(并且可能会测试项目)。

Only for "classic" references, this issue remains. 仅对于“经典”引用,此问题仍然存在。 However, if you need to import them into all projects (say you got a few .dll files from a 3rd party), you can create a Directory.Build.targets in the solution folder to add them to all projects in your solution (technically, this file is automatically imported into all projects in the directory hierarchy): 但是,如果需要将它们导入到所有项目中(例如,您从第三方获得了一些.dll文件),则可以在解决方案文件夹中创建Directory.Build.targets ,以将其添加到解决方案中的所有项目中,此文件将自动导入到目录层次结构中的所有项目中):

<Project>
  <ItemGroup>
    <Reference Include="AssemblyName">
      <HintPath>shared-libs\AssemblyName.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

(you may want to change the reference if you want the "specific version" feature or strong-name references as described in https://stackoverflow.com/a/16580870/784387 ) (如果要使用https://stackoverflow.com/a/16580870/784387中所述的“特定版本”功能或强名称引用,则可能需要更改引用)

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

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