Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c96c31

Browse filesBrowse files
authored
Merge pull request #461 from filipw/obsolete-nuget-fix
Fixed obsolete NuGet API
2 parents 7fb5bf5 + fb772ca commit 3c96c31
Copy full SHA for 3c96c31

File tree

9 files changed

+63
-58
lines changed
Filter options

9 files changed

+63
-58
lines changed

‎src/Dotnet.Script.Core/Dotnet.Script.Core.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/Dotnet.Script.Core.csproj
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn.</Description>
55
<VersionPrefix>0.29.1</VersionPrefix>
66
<Authors>filipw</Authors>
7-
<TargetFramework>netstandard2.0</TargetFramework>
7+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
88
<AssemblyName>Dotnet.Script.Core</AssemblyName>
99
<PackageId>Dotnet.Script.Core</PackageId>
1010
<PackageTags>script;csx;csharp;roslyn</PackageTags>
@@ -34,7 +34,7 @@
3434

3535
<ItemGroup>
3636
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.1.0" />
37-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
37+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
3838
<PackageReference Include="ReadLine" Version="2.0.1" />
3939
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
4040
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />

‎src/Dotnet.Script.Core/ScriptCompiler.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/ScriptCompiler.cs
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ public virtual ScriptOptions CreateScriptOptions(ScriptContext context, IList<Ru
101101
"System.Xml.Linq",
102102
"System.Net.Http",
103103
"Microsoft.CSharp");
104+
105+
// on *nix load netstandard
106+
if (!ScriptEnvironment.Default.IsWindows)
107+
{
108+
var netstandard = Assembly.Load("netstandard");
109+
if (netstandard != null)
110+
{
111+
opts = opts.AddReferences(MetadataReference.CreateFromFile(netstandard.Location));
112+
}
113+
}
104114
}
105115

106116
if (!string.IsNullOrWhiteSpace(context.FilePath))

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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj
+2-3Lines changed: 2 additions & 3 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,9 +24,8 @@
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" />
29-
3029
</ItemGroup>
3130

3231
</Project>
+41-47Lines 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;
34

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.Where(item => item is object && (item is SourceItem || item is AddItem) && item.ElementName.ToLowerInvariant() == "add").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.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net461</TargetFramework>
4+
<TargetFramework>net472</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />

‎src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NuGet.Configuration;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Linq;
56
using System.Runtime.InteropServices;
67
using Xunit;
78

@@ -213,9 +214,9 @@ public void ShouldGenerateEvaluatedNuGetConfigFile(string sourceNuGet, SettingsS
213214
{
214215
foreach (var expectedSetting in expectedSettings.Value)
215216
{
216-
var value = settings.GetValue(expectedSettings.Key, expectedSetting.Key);
217+
var value = settings.GetSection(expectedSettings.Key).Items.Cast<AddItem>().First(i => i.Key == expectedSetting.Key);
217218
var resolvedExpectedSetting = string.Format(expectedSetting.Value, sourceFolder, rootTokens);
218-
Assert.Equal(resolvedExpectedSetting, value);
219+
Assert.Equal(resolvedExpectedSetting, value.Value);
219220
}
220221
}
221222
}
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageSources>
4+
<clear />
45
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
56
</packageSources>
67
</configuration>

‎src/Dotnet.Script/Dotnet.Script.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script/Dotnet.Script.csproj
+1-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.