Replacing binary links with NuGet Links for hundreds of projects

Consider a large existing codebase with approx. 150+ solutions and 800+ C # projects. Many of them are unit tests written using NUnit. All these projects link to "nunit.framework.dll" from the "lib" folder in which the check box is selected. There are also several third-party assemblies in the "lib" folder, which has the corresponding NuGet packages.

I could manually open over 150 solutions and transfer each link to NuGet. However, this is tedious and error prone. I wrote a C # console application to analyze csproj files and determine which packages need to be installed for the corresponding project. Therefore, I know that for 300+ projects you need to install the NUnit package.

How do I programmatically automate the installation of a package in a solution that matches the same behavior as manually doing this in Visual Studio 2013? I searched everywhere and found extension , however it does not perform a full installation with dependencies, etc.

+4
source share
2 answers

Create a file packages.configwith only an entry for packages. NUnit

package.configshould look something like this to verify that the package name, version, and target information are correct.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="nunit.framework" version="2.6.3" targetFramework="net45" requireReinstallation="true" />
</packages>

extend the file analysis utility you wrote .csproj
to edit the csproj file and add tags below

  <ItemGroup>
    <None Include="packages.config" />
  </ItemGroup>

packages.config ; , , package.config

 <ItemGroup>
    <None Include="$(SolutionDir)packages.config">
       <Link>$(SolutionDir)packages.config</Link>
    </None>
  </ItemGroup>

, visual studio NuGet ; NuGet .

update-package
+3

:

Get-Project -All | foreach-object {IF (Get-Content $_.FullName | Select-String 'Reference Include="XXX"') {Install-Package XXX -ProjectName $_.FullName}}

XXX Tools->NuGet Package Manager->Package Manager Console Visual Studio.

+2

Source: https://habr.com/ru/post/1570106/


All Articles