8000 Fixed obsolete NuGet API · dotnet-script/dotnet-script@c1dd7ce · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit c1dd7ce

Browse files
committed
Fixed obsolete NuGet API
1 parent 7fb5bf5 commit c1dd7ce

File tree

4 files changed

+45
-51
lines changed

4 files changed

+45
-51
lines changed

src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RepositoryUrl>https://github.com/filipw/dotnet-script.git</RepositoryUrl>
99
<RepositoryType>git</RepositoryType>
1010
<PackageTags>script;csx;csharp;roslyn;nuget</PackageTags>
11-
<Version>0.8.0</Version>
11+
<Version>0.9.0</Version>
1212
<Description>A MetadataReferenceResolver that allows inline nuget references to be specified in script(csx) files.</Description>
1313
<Authors>dotnet-script</Authors>
1414
<Company>dotnet-script</Company>

src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<RepositoryUrl>https://github.com/filipw/dotnet-script.git</RepositoryUrl>
1212
<RepositoryType>git</RepositoryType>
1313
<PackageTags>script;csx;csharp;roslyn;omnisharp</PackageTags>
14-
<Version>0.9.0</Version>
14+
<Version>0.10.0</Version>
1515
<LangVersion>latest</LangVersion>
1616
</PropertyGroup>
1717

@@ -24,7 +24,7 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<PackageReference Include="NuGet.ProjectModel" Version="4.9.3" />
27+
<PackageReference Include="NuGet.ProjectModel" Version="5.0.0" />
2828
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
2929

3030
</ItemGroup>
Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,64 @@
11
using NuGet.Configuration;
22
using System.Collections.Generic;
3+
using System.Linq;
3< 8000 /td>4

45
namespace Dotnet.Script.DependencyModel.ProjectSystem
56
{
67
internal static class NuGetUtilities
78
{
8-
struct NuGetConfigSection
9+
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory)
910
{
10-
public string Name;
11-
public HashSet<string> KeysForPathValues;
12-
public bool AreAllValuesPaths;
11+
var sourceSettings = Settings.LoadDefaultSettings(pathToEvaluate);
12+
var targetSettings = new Settings(targetDirectory);
13+
14+
CopySection(sourceSettings, targetSettings, "config");
15+
CopySection(sourceSettings, targetSettings, "bindingRedirects");
16+
CopySection(sourceSettings, targetSettings, "packageRestore");
17+
CopySection(sourceSettings, targetSettings, "solution");
18+
CopySection(sourceSettings, targetSettings, "packageSources");
19+
CopySection(sourceSettings, targetSettings, "packageSourceCredentials");
20+
CopySection(sourceSettings, targetSettings, "apikeys");
21+
CopySection(sourceSettings, targetSettings, "disabledPackageSources");
22+
CopySection(sourceSettings, targetSettings, "activePackageSource");
23+
24+
targetSettings.SaveToDisk();
1325
}
1426

15-
static readonly NuGetConfigSection[] NuGetSections =
27+
private static void CopySection(ISettings sourceSettings, ISettings targetSettings, string sectionName)
1628
{
17-
new NuGetConfigSection { Name = "config", KeysForPathValues = new HashSet<string> { "globalPackagesFolder", "repositoryPath" } },
18-
new NuGetConfigSection { Name = "bindingRedirects" },
19-
new NuGetConfigSection { Name = "packageRestore" },
20-
new NuGetConfigSection { Name = "solution" },
21-
new NuGetConfigSection { Name = "packageSources", AreAllValuesPaths = true },
22-
new NuGetConfigSection { Name = "packageSourceCredentials" },
23-
new NuGetConfigSection { Name = "apikeys" },
24-
new NuGetConfigSection { Name = "disabledPackageSources" },
25-
new NuGetConfigSection { Name = "activePackageSource" },
26-
};
29+
var existingAddItems = sourceSettings.GetSection(sectionName)?.Items.Cast<AddItem>();
2730

28-
// Create a NuGet file containing all properties with resolved absolute paths
29-
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory)
30-
{
31-
var settings = Settings.LoadDefaultSettings(pathToEvaluate);
32-
var target = new Settings(targetDirectory);
31+
if (existingAddItems == null)
32+
{
33+
return;
34+
}
3335

34-
var valuesToSet = new List<SettingValue>();
35-
foreach (var section in NuGetSections)
36+
foreach (var addItem in existingAddItems)
3637
{
37-
// Resolve properly path values
38-
valuesToSet.Clear();
39-
if (section.AreAllValuesPaths)
38+
if (ShouldResolvePath(sectionName, addItem.Key))
4039
{
41-
// All values are paths
42-
var values = settings.GetSettingValues(section.Name, true);
43-
valuesToSet.AddRange(values);
40+
targetSettings.AddOrUpdate(sectionName, new AddItem(addItem.Key, addItem.GetValueAsPath()));
4441
}
4542
else
4643
{
47-
var values = settings.GetSettingValues(section.Name, false);
48-
if (section.KeysForPathValues != null)
49-
{
50-
// Some values are path
51-
foreach (var value in values)
52-
{
53-
if (section.KeysForPathValues.Contains(value.Key))
54-
{
55-
var val = settings.GetValue(section.Name, value.Key, true);
56-
value.Value = val;
57-
}
58-
59-
valuesToSet.Add(value);
60-
}
61-
}
62-
else
63-
// All values are not path
64-
valuesToSet.AddRange(values);
44+
targetSettings.AddOrUpdate(sectionName, addItem);
6545
}
66-
target.SetValues(section.Name, valuesToSet);
6746
}
6847
}
48+
49+
private static bool ShouldResolvePath(string sectionName, string key)
50+
{
51+
if (sectionName == "packageSources")
52+
{
53+
return true;
54+
}
55+
56+
if (sectionName == "config")
57+
{
58+
return key == "globalPackagesFolder" || key == "repositoryPath";
59+
}
60+
61+
return false;
62+
}
6963
}
7064
}

src/Dotnet.Script/Dotnet.Script.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>Dotnet CLI tool allowing you to run C# (CSX) scripts.</Description>
4-
<VersionPrefix>0.29.1</VersionPrefix>
4+
<VersionPrefix>0.30.0</VersionPrefix>
55
<Authors>filipw</Authors>
66
<PackageId>Dotnet.Script</PackageId>
77
<TargetFramework>netcoreapp2.1</TargetFramework>

0 commit comments

Comments
 (0)
0