yzorg
yzorg

Reputation: 4450

Visual Studio dotnet core copy and paste references

I've known about copy/paste references in Visual Studio since 2010/2012. Has this been updated to work with 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?

Upvotes: 0

Views: 353

Answers (2)

yzorg
yzorg

Reputation: 4450

Maybe now that dotnet add package is available, we don't need copy/paste references in VS?

"Add Google social login" walkthrough for ASP.NET Core 2.0 suggests using the dotnet CLI to add a package reference:

  • To install with .NET Core CLI, execute the following in your project directory:

    dotnet add package Microsoft.AspNetCore.Authentication.Google

source: https://learn.microsoft.com/en-us/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.

Upvotes: 1

Martin Ullrich
Martin Ullrich

Reputation: 100601

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).

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. 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).

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):

<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)

Upvotes: 0

Related Questions