Skip to content

Fixed obsolete NuGet API #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Dotnet.Script.Core/Dotnet.Script.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn.</Description>
<VersionPrefix>0.29.1</VersionPrefix>
<Authors>filipw</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<AssemblyName>Dotnet.Script.Core</AssemblyName>
<PackageId>Dotnet.Script.Core</PackageId>
<PackageTags>script;csx;csharp;roslyn</PackageTags>
Expand Down Expand Up @@ -34,7 +34,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="ReadLine" Version="2.0.1" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />
Expand Down
10 changes: 10 additions & 0 deletions src/Dotnet.Script.Core/ScriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public virtual ScriptOptions CreateScriptOptions(ScriptContext context, IList<Ru
"System.Xml.Linq",
"System.Net.Http",
"Microsoft.CSharp");

// on *nix load netstandard
if (!ScriptEnvironment.Default.IsWindows)
{
var netstandard = Assembly.Load("netstandard");
if (netstandard != null)
{
opts = opts.AddReferences(MetadataReference.CreateFromFile(netstandard.Location));
}
}
}

if (!string.IsNullOrWhiteSpace(context.FilePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RepositoryUrl>https://github.com/filipw/dotnet-script.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>script;csx;csharp;roslyn;nuget</PackageTags>
<Version>0.8.0</Version>
<Version>0.9.0</Version>
<Description>A MetadataReferenceResolver that allows inline nuget references to be specified in script(csx) files.</Description>
<Authors>dotnet-script</Authors>
<Company>dotnet-script</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RepositoryUrl>https://github.com/filipw/dotnet-script.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>script;csx;csharp;roslyn;omnisharp</PackageTags>
<Version>0.9.0</Version>
<Version>0.10.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -24,9 +24,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NuGet.ProjectModel" Version="4.9.3" />
<PackageReference Include="NuGet.ProjectModel" Version="5.0.0" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />

</ItemGroup>

</Project>
88 changes: 41 additions & 47 deletions src/Dotnet.Script.DependencyModel/ProjectSystem/NuGetUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
using NuGet.Configuration;
using System.Collections.Generic;
using System.Linq;

namespace Dotnet.Script.DependencyModel.ProjectSystem
{
internal static class NuGetUtilities
{
struct NuGetConfigSection
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory)
{
public string Name;
public HashSet<string> KeysForPathValues;
public bool AreAllValuesPaths;
var sourceSettings = Settings.LoadDefaultSettings(pathToEvaluate);
var targetSettings = new Settings(targetDirectory);

CopySection(sourceSettings, targetSettings, "config");
CopySection(sourceSettings, targetSettings, "bindingRedirects");
CopySection(sourceSettings, targetSettings, "packageRestore");
CopySection(sourceSettings, targetSettings, "solution");
CopySection(sourceSettings, targetSettings, "packageSources");
CopySection(sourceSettings, targetSettings, "packageSourceCredentials");
CopySection(sourceSettings, targetSettings, "apikeys");
CopySection(sourceSettings, targetSettings, "disabledPackageSources");
CopySection(sourceSettings, targetSettings, "activePackageSource");

targetSettings.SaveToDisk();
}

static readonly NuGetConfigSection[] NuGetSections =
private static void CopySection(ISettings sourceSettings, ISettings targetSettings, string sectionName)
{
new NuGetConfigSection { Name = "config", KeysForPathValues = new HashSet<string> { "globalPackagesFolder", "repositoryPath" } },
new NuGetConfigSection { Name = "bindingRedirects" },
new NuGetConfigSection { Name = "packageRestore" },
new NuGetConfigSection { Name = "solution" },
new NuGetConfigSection { Name = "packageSources", AreAllValuesPaths = true },
new NuGetConfigSection { Name = "packageSourceCredentials" },
new NuGetConfigSection { Name = "apikeys" },
new NuGetConfigSection { Name = "disabledPackageSources" },
new NuGetConfigSection { Name = "activePackageSource" },
};
var existingAddItems = sourceSettings.GetSection(sectionName)?.Items.Where(item => item is object && (item is SourceItem || item is AddItem) && item.ElementName.ToLowerInvariant() == "add").Cast<AddItem>();

// Create a NuGet file containing all properties with resolved absolute paths
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory)
{
var settings = Settings.LoadDefaultSettings(pathToEvaluate);
var target = new Settings(targetDirectory);
if (existingAddItems == null)
{
return;
}

var valuesToSet = new List<SettingValue>();
foreach (var section in NuGetSections)
foreach (var addItem in existingAddItems)
{
// Resolve properly path values
valuesToSet.Clear();
if (section.AreAllValuesPaths)
if (ShouldResolvePath(sectionName, addItem.Key))
{
// All values are paths
var values = settings.GetSettingValues(section.Name, true);
valuesToSet.AddRange(values);
targetSettings.AddOrUpdate(sectionName, new AddItem(addItem.Key, addItem.GetValueAsPath()));
}
else
{
var values = settings.GetSettingValues(section.Name, false);
if (section.KeysForPathValues != null)
{
// Some values are path
foreach (var value in values)
{
if (section.KeysForPathValues.Contains(value.Key))
{
var val = settings.GetValue(section.Name, value.Key, true);
value.Value = val;
}

valuesToSet.Add(value);
}
}
else
// All values are not path
valuesToSet.AddRange(values);
targetSettings.AddOrUpdate(sectionName, addItem);
}
target.SetValues(section.Name, valuesToSet);
}
}

private static bool ShouldResolvePath(string sectionName, string key)
{
if (sectionName == "packageSources")
{
return true;
}

if (sectionName == "config")
{
return key == "globalPackagesFolder" || key == "repositoryPath";
}

return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
Expand Down
5 changes: 3 additions & 2 deletions src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NuGet.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;

Expand Down Expand Up @@ -213,9 +214,9 @@ public void ShouldGenerateEvaluatedNuGetConfigFile(string sourceNuGet, SettingsS
{
foreach (var expectedSetting in expectedSettings.Value)
{
var value = settings.GetValue(expectedSettings.Key, expectedSetting.Key);
var value = settings.GetSection(expectedSettings.Key).Items.Cast<AddItem>().First(i => i.Key == expectedSetting.Key);
var resolvedExpectedSetting = string.Format(expectedSetting.Value, sourceFolder, rootTokens);
Assert.Equal(resolvedExpectedSetting, value);
Assert.Equal(resolvedExpectedSetting, value.Value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion src/Dotnet.Script/Dotnet.Script.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Dotnet CLI tool allowing you to run C# (CSX) scripts.</Description>
<VersionPrefix>0.29.1</VersionPrefix>
<VersionPrefix>0.30.0</VersionPrefix>
<Authors>filipw</Authors>
<PackageId>Dotnet.Script</PackageId>
<TargetFramework>netcoreapp2.1</TargetFramework>
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy