Programmatically create package.config

I programmatically generate a Visual Studio project. This project requires some Nuget packages.

I create a file called packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>

When you start the project for the first time, it will download the package. The problem is that if a new version is released, it will always download version 7.0.1.

Is there any way to say to get the latest version? Is there a way to programmatically ask NuGet what is the latest version so that I can add it to my project when I generated it?

I tried to remove the version and add version = "*" and did not work.

Update

<package id="Newtonsoft.Json"  targetFramework="net45" />

gives the following error:

NuGet package restore error for SampleProject project: syntax version value '' cannot be executed from 'packages.config'

<package id="Newtonsoft.Json" version="*"  targetFramework="net45" />

2 NuGet SampleProject: '*' 'packages.config'

, . , - - , .

+4
1

NuGet, , :

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="SomePackage" version="2.1.0" allowedVersions="[2,3)" />
</packages>

, , . , , . . : https://docs.nuget.org/create/versioning

packages.config .

- vsix, nuget vsix , , .

NuGet , . Update-Package 'YourPackageName' / IWizard, , NuGet .

+1

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


All Articles