sdgfsdh
sdgfsdh

Reputation: 37025

In an MS Build project file, can a Nuget package reference be given a path?

I have a Nuget package that is downloaded to a non-standard location in my project folder.

Is it possible to reference this package in an fsproj or csproj file?

Something like:

<ItemGroup>
  <PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0">
    <HintPath>./external/packages/Contoso.Utility.UsefulStuff.3.6.0/</HintPath>
  </PackageReference>
</ItemGroup>

Upvotes: 1

Views: 860

Answers (1)

JL0PD
JL0PD

Reputation: 4488

Nuget can have multiple sources for packages, that can be configured with a nuget.config file. Source can be either URL of some site, like nuget.org or private feed from gitlab, or it can be path to local directory, like C:/Packages/.

You should create nuget.config file in a root of repository with following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!-- Make sure everyone have same sources for more reliability -->
    <clear /> 
    
    <!-- Add default nuget source, since we removed it -->
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    
    <!-- Add new source that will point to directory with *.nupkg files. 
         Parameter 'key' can have arbitrary text -->
    <add key="localFiles" value="./external/packages/" />
  </packageSources>
</configuration>

Upvotes: 2

Related Questions