最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - Is it possible to have nuget delay download until build? - Stack Overflow

programmeradmin1浏览0评论

I have a project that needs a reference to a nuget package, containing a number of dlls that it will use later.

When I install the nuget package, it instantly copies all the libraries into the correct location. However, the point of this exercise is to keep them out of the project's git repository, and for nuget to do the download while building.

Is this possible?

This is my nuspec:

<?xml version="1.0"?>
<package xmlns=".xsd">
  <metadata>
    <version>1.0.0</version>
    <authors>MyCompany Ltd</authors>
    <owners>MyCompany Ltd</owners>
    <id>MyCompany.ReferencedLibraries</id>
    <title>MyCompany.ReferencedLibraries</title>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Libraries referenced by my project</description>
    <copyright>Copyright MyCompany Ltd 2025</copyright>
    <dependencies />
  </metadata>
  <files>
    <file src="Package\**" target="content\Lib" />
  </files>
</package>

... all the files are in the Package directory and are to be copied into the project's Lib directory within the project's code base.

I have noticed that if I delete the files after installation, and build again, it doesn't restore the files automatically, so adding them to .gitignore won't help - even though I thought this was how nuget worked.

Could the difference be pointing the target the content folder?

I have a project that needs a reference to a nuget package, containing a number of dlls that it will use later.

When I install the nuget package, it instantly copies all the libraries into the correct location. However, the point of this exercise is to keep them out of the project's git repository, and for nuget to do the download while building.

Is this possible?

This is my nuspec:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft/packaging/2011/08/nuspec.xsd">
  <metadata>
    <version>1.0.0</version>
    <authors>MyCompany Ltd</authors>
    <owners>MyCompany Ltd</owners>
    <id>MyCompany.ReferencedLibraries</id>
    <title>MyCompany.ReferencedLibraries</title>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Libraries referenced by my project</description>
    <copyright>Copyright MyCompany Ltd 2025</copyright>
    <dependencies />
  </metadata>
  <files>
    <file src="Package\**" target="content\Lib" />
  </files>
</package>

... all the files are in the Package directory and are to be copied into the project's Lib directory within the project's code base.

I have noticed that if I delete the files after installation, and build again, it doesn't restore the files automatically, so adding them to .gitignore won't help - even though I thought this was how nuget worked.

Could the difference be pointing the target the content folder?

Share Improve this question asked Mar 5 at 23:00 komodospkomodosp 3,6584 gold badges37 silver badges68 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Not exactly answering your question, but if you want to keep NuGet packages from being pushed to the GIT repository ever, add an entry to your .gitignore file. Even after building the project and the NuGet packages have been downloaded, none of these files will be pushed to the GIT repository. Hope this helps.

the point of this exercise is to keep them out of the project's git repository

From looking at this document Omitting NuGet packages in source control systems, we can know that

Developers typically omit NuGet packages from their source control repositories and rely instead on package restore to reinstall a project's dependencies before a build.

As @areyesram said, you can use .gitignore file.

For example:

# Ignore NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*

Docs Referred:

Omitting NuGet packages in source control systems

Automatically check for missing packages during build

发布评论

评论列表(0)

  1. 暂无评论