Coder Social home page Coder Social logo

benmccallum / dotnet-references Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 3.0 81 KB

A dotnet global tool for working with references in solution and project files

License: MIT License

C# 100.00%
dotnet-global-tool csproj-tooling dotnet-core docker github-actions

dotnet-references's Introduction

dotnet references

Nuget Buy Me A Coffee

A dotnet global tool that aids with bulk solution and project file references changes and related directory organisation.

(Formerly dotnet-fix-references, see prior documentation for it here.)

Installation

dotnet tool install --global dotnet-references

Note: If using this in a scripted process you want to be consistent (like a build), you should pin to a specific version with --version x.y.z.

Usage

Usage: dotnet-references <Mode> [options]

Arguments:
  Mode                                       The mode to run (fix or internalise)

Options:
  -ep|--entry-point                          The entry point to use (a .sln file or a directory)
  -wd|--working-directory                    The working directory to use (under which all .sln and .csproj files are contained). 
                                             If not provided, defaults to directory of entry point.
  -rupf|--remove-unreferenced-project-files  Should unreferenced project files be removed?
                                             (Caution! Deletes files! Only supported in fix mode).
  -reig|--remove-empty-item-groups           Should ItemGroup elements in project files that are empty be removed?
                                             (Only supported in internalise mode).
  -?|-h|--help                               Show help information

Supports the following modes which have varying use cases.

Mode 1: Fix

This mode can fix references between solution files and projects in one of two ways.

โš ๏ธ If the dotnet cli complains with "Specify which project file to use because this '...' contains more than one project file.", you've run into a limitation of the dotnet cli. A workaround is to execute from any random directory and utilise the -ep and -wd args. (eg. mkdir temp && cd temp && dotnet references fix -ep ../ -wd .. -rupf (or -ep ../Company.Project.sln -wd ..)).

Directory-first

By passing a directory as the entry, the tool will assume that the current directory structure is the source of truth and will fix all project references inside all .sln and .csproj files to the correct relative path.

dotnet references fix -ep ./src

Use cases: You have moved your source code into a new folder structure (via a script or otherwise) and don't want to manually updates all your project references in .sln and .csproj files. (Project file names must be the same).

File-first

By passing a .sln file, the tool will assume that it, and the path it references .csproj files, is the source of truth; thus moving the .csproj files into the correct directory structure.

dotnet references fix -ep Company.Project.sln

Use cases:

  1. Overcoming Dockerfile COPY globbing limitations... See here.

Mode 2: Internalise (PackageReference --> ProjectReference)

This mode "internalises" references, by turning package references to project references. (The project name must be the same as the package name).

dotnet references internalise -wd ./src

Use cases:

  1. You've consolidated separate projects (and packages) into a mono repo and want to swap all package references to local project references where possible.

Note: It currently doesn't handle transitive dependencies (dependencies of dependencies), which you'll need to add manually.

Word of warning

This tool updates/deletes files in-place. Backup anything you care about before running this tool.

Feature backlog

  1. Support fix mode w/ .csproj entry

dotnet-references's People

Contributors

adamjez avatar anthony-keller avatar benmccallum avatar espenrl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dotnet-references's Issues

Error running fix mode

I follow the steps as outlined. I end up with a flat root source folder with one sln file and several csproj files. However, when I run dotnet references fix I get the following error, which seems to originate from dotnet itself. Any ideas how to fix?

Step 15/25 : RUN dotnet references fix -ep MySolution.sln -wd . -rupf
---> Running in b13ea6e2a0a9
Specify which project file to use because this '/src' contains more than one project file.
The command '/bin/sh -c dotnet references fix -ep MySolution.sln -wd . -rupf' returned a non-zero code: 1

Here's my dockerfile build phase that results in the error:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build

#Set up dotnet tools
ENV PATH="${PATH}:/root/.dotnet/tools"
RUN dotnet tool install -g dotnet-references

WORKDIR /src
COPY *.sln ./
COPY */*.csproj ./
RUN dotnet references fix -ep MySolution.sln -wd . -rupf

Mixed backslash and forward slash issue

Hi. Thanks for this tool! I use it for the docker restore issue.

I have encountered a small issue on a big windows-developed project compiled on Linux machines.

On

var lastSlashIndex = input.LastIndexOf('\\');

You use the windows separator instead of Path.DirectorySeparatorChar. So whenever we have linux-style separators, we get a Could not find csproj file path for: 'Include="../xxxProject/xxxProject.csproj'. error.

However, as many projects actually a happy mix of forward and back slashes, I believe the best way to deal with this is to String.Replace all back with forward, as you actually already do in FixLocationsOfProjectsProcessor.cs.

Thanks for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.