question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a dotnet-ref command to enable adding references to the project file

See original GitHub issue

The CLI needs to provide a way for users to add project and package references to the project file.

Below is a mini-spec of the command.

Note: this is a mini-spec, more detailed documents will be available on docs.microsoft.com

Usage

dotnet &lt;operation&gt; <project_or_solution> &lt;command&gt; &lt;project_or_package&gt; <args>

Operations

  • add
  • list
  • remove
  • update

Commands

  • project
  • package

Arguments

  • <operation>
    • One of the operation from the previous list
  • <command>
    • One of the commands from the above list
  • <project_or_solution>
    • A project or a solution path
  • <project_or_package>
    • Path to the project file to include in the project or a package ID for package references
  • <args>
    • Arguments to the command

Defaults

  • If the <project> is not present, we will try to see if there is a project in the current directory; if there is, it will be added, if not, an error is displayed
  • If the <project_or_solution> is not present, we will check the current directory for either a project file or a sln file.
    • If neither are found, an error is displayed
    • If more than one is found or if there is both sln and a project file present, an error is displayed prompting the user to specify which file the operation should work on.

Arguments

Arguments are here mostly for the package command. Arguments are the following:

  • --version | -v - provides a version for the package to be added. If none is specified, latest is assumed.
  • --pre-release | -p - specify whether to check for pre-release packages as well.
  • --frameworks | -f - place the package reference under the specified framework.
  • --no-restore | -n - do not restore after the operation completes.

Notes

  • This command adds a project to a solution if it works on an SLN file. In case a project file, it will add a <ProjectReference> to the project in question.
  • The command will make absolute paths of the project being added relative to the solution file/project being added. This is done to avoid messy breaks when moving machines.

Examples

  • dotnet add project "../path/to/project.csproj"
    • Add a project found at the specified path to the project file
  • `dotnet remove package Newtonsoft.json
    • Remove a package with the specified ID
  • dotnet add package package.id --version 1.0.0
    • Add the package with package ID of “package.id” with the specified version.
  • dotnet list path/to/project.csproj package
    • List out all of the packages in the specified project file

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
enricosadacommented, Dec 6, 2016

Honestly, I don’t see a need for a specialized command just to add a <PackageReference> tag to the csproj; I do it by hand and have no problems

the command is for cli, but is also useful because you can automate things (from ide/tools or script).

  • dotnet new
  • dotnet ref add Newtonsoft.Json
  • copy Program.fs serializator example
  • dotnet run
1reaction
enricosadacommented, Nov 17, 2016

It’s possible to add also an option to set also PrivateAssets property for PackageReference? it’s useful for adding sdk packages who need <PrivateAssets>All</PrivateAssets>

So something like --private-assets "All" ? @blackdwarf if ok, i can add that (i need that for adding fsharp sdk package 😄, so personal interests) but i think is useful for scripting/tutorial to add dotnet test sdk packages So like

  • create console with dotnet new
  • add ref to xunit/nunit sdk
  • add ref to xunit/nunit packages
  • go!
Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet add reference command - .NET CLI
The dotnet add reference command provides a convenient option to add project-to-project references.
Read more >
Add a dotnet-ref command to enable adding references ...
This command adds a project to a solution if it works on an SLN file. In case a project file, it will add...
Read more >
1.5: Adding Other Projects and References - DotNet-302- ...
Add Project References. Navigate into your EFConnect.API project in your command line. dotnet add reference ../EFConnect.Data/EFConnect.Data.csproj.
Read more >
Manage Project and Package References with .net CLI
The dotnet add package provides a convenient option to add a package reference to a project file. After running the command, a compatibility ......
Read more >
How to add a .dll reference to a project in Visual Studio
I see 1) A top menu "Project --> Add Reference..." 2) on side of screen, Solution Explorer, myProjectName, References. I can right click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found