Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Lowercase ID and version in NuGet global packages directory
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed May 4, 2016
1 parent 11a0017 commit e64b514
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 46 deletions.
1 change: 1 addition & 0 deletions NuGet.Config
Expand Up @@ -3,6 +3,7 @@
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nugetbuild-jver" value="https://www.myget.org/F/nugetbuild-jver/api/v3/index.json" />
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Expand Down
96 changes: 93 additions & 3 deletions scripts/dotnet-cli-build/CompileTargets.cs
Expand Up @@ -324,7 +324,7 @@ public static BuildTargetResult CompileStage1(BuildTargetContext c)
Directory.CreateDirectory(Dirs.Stage1);

CopySharedHost(Dirs.Stage1);
PublishSharedFramework(c, Dirs.Stage1, DotNetCli.Stage0);
PublishSharedFramework(c, Dirs.Stage1, DotNetCli.Stage0, nuGetVersion: "3.5.0-rc-1233");
var result = CompileCliSdk(c,
dotnet: DotNetCli.Stage0,
outputDir: Dirs.Stage1);
Expand All @@ -350,7 +350,10 @@ public static BuildTargetResult CompileStage2(BuildTargetContext c)
}
Directory.CreateDirectory(Dirs.Stage2);

PublishSharedFramework(c, Dirs.Stage2, DotNetCli.Stage1);
// Restore again, with Stage1.
Restore(c, DotNetCli.Stage1);

PublishSharedFramework(c, Dirs.Stage2, DotNetCli.Stage1, nuGetVersion: null);
CopySharedHost(Dirs.Stage2);
var result = CompileCliSdk(c,
dotnet: DotNetCli.Stage1,
Expand Down Expand Up @@ -470,7 +473,7 @@ private static void CopySharedHost(string outputDir)
Path.Combine(outputDir, DotnetHostFxrBaseName), true);
}

public static void PublishSharedFramework(BuildTargetContext c, string outputDir, DotNetCli dotnetCli)
public static void PublishSharedFramework(BuildTargetContext c, string outputDir, DotNetCli dotnetCli, string nuGetVersion)
{
string SharedFrameworkTemplateSourceRoot = Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework");
string SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
Expand Down Expand Up @@ -539,6 +542,31 @@ public static void PublishSharedFramework(BuildTargetContext c, string outputDir
var runtimeGraphGeneratorProject = Path.Combine(Dirs.RepoRoot, "tools", runtimeGraphGeneratorName);
var runtimeGraphGeneratorOutput = Path.Combine(Dirs.Output, "tools", runtimeGraphGeneratorName);

// Override the NuGet version the RuntimeGraphGenerator depends on.
var originals = new[]
{
new { Path = (string)null, Content = (byte[])null }
};
if (nuGetVersion != null)
{
originals = new[]
{
Path.Combine("src", "dotnet"),
Path.Combine("src", "Microsoft.DotNet.Cli.Utils"),
Path.Combine("src", "Microsoft.DotNet.ProjectModel"),
Path.Combine("tools", runtimeGraphGeneratorName)
}
.Select(p => Path.Combine(Dirs.RepoRoot, p, "project.json"))
.Select(p => new
{
Path = p,
Content = UpdateNuGetVersion(c, p, nuGetVersion)
})
.ToArray();

Restore(c, dotnetCli);
}

dotnetCli.Publish(
"--output", runtimeGraphGeneratorOutput,
runtimeGraphGeneratorProject).Execute().EnsureSuccessful();
Expand All @@ -547,6 +575,16 @@ public static void PublishSharedFramework(BuildTargetContext c, string outputDir
Cmd(runtimeGraphGeneratorExe, "--project", SharedFrameworkSourceRoot, "--deps", destinationDeps, runtimeGraphGeneratorRuntime)
.Execute()
.EnsureSuccessful();

if (nuGetVersion != null)
{
foreach (var original in originals)
{
RestoreNuGetVersion(c, original.Path, original.Content);
}

Restore(c, dotnetCli);
}
}
else
{
Expand Down Expand Up @@ -584,6 +622,58 @@ public static void PublishSharedFramework(BuildTargetContext c, string outputDir
File.WriteAllText(Path.Combine(SharedFrameworkNameAndVersionRoot, ".version"), content);
}

private static byte[] UpdateNuGetVersion(BuildTargetContext c, string projectJsonPath, string version)
{
c.Warn($"Setting the NuGet version in {projectJsonPath} to {version}.");

var encoding = new UTF8Encoding(false);

var originalBytes = File.ReadAllBytes(projectJsonPath);
var originalJson = encoding.GetString(originalBytes);
var projectJson = JsonConvert.DeserializeObject<JObject>(originalJson);
var dependencies = (JObject)projectJson["dependencies"];
foreach (var property in dependencies.Properties())
{
if (property.Name.StartsWith("NuGet."))
{
if (property.Value.Type == JTokenType.String)
{
property.Value = version;
}
else
{
property.Value["version"] = version;
}
}
}

var newJson = JsonConvert.SerializeObject(projectJson, Formatting.Indented);
var newBytes = encoding.GetBytes(newJson);

File.WriteAllBytes(projectJsonPath, newBytes);

return originalBytes;
}

private static void RestoreNuGetVersion(BuildTargetContext c, string projectJsonPath, byte[] originalBytes)
{
c.Warn($"Restoring the original NuGet version to {projectJsonPath}.");

File.WriteAllBytes(projectJsonPath, originalBytes);
}

private static void Restore(BuildTargetContext c, DotNetCli dotnetCli)
{
dotnetCli.Restore("--verbosity", "verbose", "--disable-parallel", "--fallbacksource", Dirs.CorehostLocalPackages)
.WorkingDirectory(Path.Combine(Dirs.RepoRoot, "src"))
.Execute()
.EnsureSuccessful();
dotnetCli.Restore("--verbosity", "verbose", "--disable-parallel", "--infer-runtimes")
.WorkingDirectory(Path.Combine(Dirs.RepoRoot, "tools"))
.Execute()
.EnsureSuccessful();
}

/// <summary>
/// Generates the real shared framework project that will get published.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-dependencies/project.json
Expand Up @@ -9,7 +9,7 @@
"Microsoft.CSharp": "4.0.1-rc2-24027",
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
"Microsoft.DotNet.Cli.Build.Framework": "1.0.0-*",
"NuGet.Versioning": "3.5.0-rc-1233",
"NuGet.Versioning": "3.5.0-rc-759",
"Newtonsoft.Json": "7.0.1",
"Octokit": "0.18.0",
"Microsoft.Net.Http": "2.2.29"
Expand Down
Expand Up @@ -55,7 +55,7 @@ public string GetLockFilePath(string packageId, NuGetVersion version, NuGetFrame

return Path.Combine(
GetBaseToolPath(packageId),
version.ToNormalizedString(),
version.ToNormalizedString().ToLowerInvariant(),
framework.GetShortFolderName(),
"project.lock.json");
}
Expand All @@ -65,7 +65,7 @@ private string GetBaseToolPath(string packageId)
return Path.Combine(
_packagesDirectory,
".tools",
packageId);
packageId.ToLowerInvariant());
}

private IEnumerable<NuGetVersion> GetAvailableToolVersions(string packageId)
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.DotNet.Cli.Utils/project.json
Expand Up @@ -6,10 +6,10 @@
},
"dependencies": {
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"NuGet.Versioning": "3.5.0-rc-1233",
"NuGet.Packaging": "3.5.0-rc-1233",
"NuGet.Frameworks": "3.5.0-rc-1233",
"NuGet.ProjectModel": "3.5.0-rc-1233"
"NuGet.Versioning": "3.5.0-rc-759",
"NuGet.Packaging": "3.5.0-rc-759",
"NuGet.Frameworks": "3.5.0-rc-759",
"NuGet.ProjectModel": "3.5.0-rc-759"
},
"frameworks": {
"net451": {
Expand Down
Expand Up @@ -16,6 +16,8 @@ public class LockFilePackageLibrary

public string Sha512 { get; set; }

public string Path { get; set; }

public IList<string> Files { get; set; } = new List<string>();
}
}
1 change: 1 addition & 0 deletions src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs
Expand Up @@ -151,6 +151,7 @@ private void ReadLibrary(JObject json, LockFile lockFile)
Version = version,
IsServiceable = ReadBool(value, "serviceable", defaultValue: false),
Sha512 = ReadString(value["sha512"]),
Path = value.Value<string>("path"),
Files = ReadPathArray(value["files"], ReadString)
});
}
Expand Down
Expand Up @@ -170,11 +170,6 @@ public IList<DiagnosticMessage> GetAllDiagnostics()
continue;
}

if (library.Identity.Version.IsPrerelease && !versionRange.IncludePrerelease)
{
versionRange = VersionRange.SetIncludePrerelease(versionRange, includePrerelease: true);
}

if (item.Library != library && !versionRange.Satisfies(library.Identity.Version))
{
var message = $"Dependency conflict. {item.Library.Identity} expected {FormatLibraryRange(item.Dependency)} but got {library.Identity.Version}";
Expand Down
Expand Up @@ -15,11 +15,13 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
{
public class PackageDependencyProvider
{
private readonly string _packagesPath;
private readonly VersionFolderPathResolver _packagePathResolver;
private readonly FrameworkReferenceResolver _frameworkReferenceResolver;

public PackageDependencyProvider(string packagesPath, FrameworkReferenceResolver frameworkReferenceResolver)
{
_packagesPath = packagesPath;
_packagePathResolver = new VersionFolderPathResolver(packagesPath);
_frameworkReferenceResolver = frameworkReferenceResolver;
}
Expand All @@ -40,7 +42,16 @@ public PackageDescription GetDescription(NuGetFramework targetFramework, LockFil
var dependencies = new List<LibraryRange>(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count);
PopulateDependencies(dependencies, targetLibrary, targetFramework);

var path = _packagePathResolver.GetInstallPath(package.Name, package.Version);
string path;
if (package.Path != null)
{
path = Path.Combine(_packagesPath, package.Path);
}
else
{
path = _packagePathResolver.GetInstallPath(package.Name, package.Version);
}

var exists = Directory.Exists(path);

if (exists)
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.DotNet.ProjectModel/project.json
Expand Up @@ -7,8 +7,8 @@
"dependencies": {
"Microsoft.Extensions.DependencyModel": "1.0.0-*",
"Newtonsoft.Json": "7.0.1",
"NuGet.Packaging": "3.5.0-rc-1233",
"NuGet.RuntimeModel": "3.5.0-rc-1233",
"NuGet.Packaging": "3.5.0-rc-759",
"NuGet.RuntimeModel": "3.5.0-rc-759",
"System.Reflection.Metadata": "1.3.0-rc2-24027"
},
"frameworks": {
Expand Down
Expand Up @@ -53,7 +53,8 @@ public bool TryResolveAssemblyPaths(CompilationLibrary library, List<string> ass
if (ResolverUtils.TryResolvePackagePath(_fileSystem, library, _packageCacheDirectory, out packagePath))
{
var hashAlgorithm = library.Hash.Substring(0, hashSplitterPos);
var cacheHashPath = Path.Combine(packagePath, $"{library.Name}.{library.Version}.nupkg.{hashAlgorithm}");
var cacheHashFileName = $"{library.Name.ToLowerInvariant()}.{library.Version.ToLowerInvariant()}.nupkg.{hashAlgorithm}";
var cacheHashPath = Path.Combine(packagePath, cacheHashFileName);

if (_fileSystem.File.Exists(cacheHashPath) &&
_fileSystem.File.ReadAllText(cacheHashPath) == library.Hash.Substring(hashSplitterPos + 1))
Expand Down
Expand Up @@ -12,7 +12,11 @@ internal static class ResolverUtils
{
internal static bool TryResolvePackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath, out string packagePath)
{
packagePath = Path.Combine(basePath, library.Name, library.Version);
packagePath = Path.Combine(
basePath,
library.Name.ToLowerInvariant(),
library.Version.ToLowerInvariant());

if (fileSystem.Directory.Exists(packagePath))
{
return true;
Expand Down
12 changes: 6 additions & 6 deletions src/corehost/cli/deps_entry.cpp
Expand Up @@ -104,8 +104,8 @@ bool deps_entry_t::to_full_path(const pal::string_t& base, pal::string_t* str) c
}

pal::string_t new_base = base;
append_path(&new_base, library_name.c_str());
append_path(&new_base, library_version.c_str());
append_path(&new_base, pal::to_lower(library_name).c_str());
append_path(&new_base, pal::to_lower(library_version).c_str());

return to_rel_path(new_base, str);
}
Expand Down Expand Up @@ -154,18 +154,18 @@ bool deps_entry_t::to_hash_matched_path(const pal::string_t& base, pal::string_t
// Build the nupkg file name. Just reserve approx 8 char_t's for the algorithm name.
pal::string_t nupkg_filename;
nupkg_filename.reserve(library_name.length() + 1 + library_version.length() + 16);
nupkg_filename.append(library_name);
nupkg_filename.append(pal::to_lower(library_name));
nupkg_filename.append(_X("."));
nupkg_filename.append(library_version);
nupkg_filename.append(pal::to_lower(library_version));
nupkg_filename.append(_X(".nupkg."));
nupkg_filename.append(library_hash.substr(0, pos));

// Build the hash file path str.
pal::string_t hash_file;
hash_file.reserve(base.length() + library_name.length() + library_version.length() + nupkg_filename.length() + 3);
hash_file.assign(base);
append_path(&hash_file, library_name.c_str());
append_path(&hash_file, library_version.c_str());
append_path(&hash_file, pal::to_lower(library_name).c_str());
append_path(&hash_file, pal::to_lower(library_version).c_str());
append_path(&hash_file, nupkg_filename.c_str());

// Read the contents of the hash file.
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet/project.json
Expand Up @@ -17,10 +17,10 @@
],
"dependencies": {
"NuGet.Commands": {
"version": "3.5.0-rc-1233",
"version": "3.5.0-rc-759",
"exclude": "compile"
},
"NuGet.CommandLine.XPlat": "3.5.0-rc-1233",
"NuGet.CommandLine.XPlat": "3.5.0-rc-759",
"Newtonsoft.Json": "7.0.1",
"System.Text.Encoding.CodePages": "4.0.1-rc2-24027",
"System.Diagnostics.FileVersionInfo": "4.0.0-rc2-24027",
Expand Down
Expand Up @@ -167,7 +167,7 @@ public void It_resolves_tools_whose_package_name_is_different_than_dll_name()
var command = factory.Create("dotnet-tool-with-output-name", null);

command.CommandArgs.Should().Contain(
Path.Combine("ToolWithOutputName", "1.0.0", "lib", "netcoreapp1.0", "dotnet-tool-with-output-name.dll"));
Path.Combine("toolwithoutputname", "1.0.0", "lib", "netcoreapp1.0", "dotnet-tool-with-output-name.dll"));
}
}
}
8 changes: 4 additions & 4 deletions test/Microsoft.DotNet.Cli.Utils.Tests/project.json
Expand Up @@ -11,10 +11,10 @@
},
"System.Diagnostics.TraceSource": "4.0.0-rc2-24027",
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
"NuGet.Versioning": "3.5.0-rc-1233",
"NuGet.Packaging": "3.5.0-rc-1233",
"NuGet.Frameworks": "3.5.0-rc-1233",
"NuGet.ProjectModel": "3.5.0-rc-1233",
"NuGet.Versioning": "3.5.0-rc-759",
"NuGet.Packaging": "3.5.0-rc-759",
"NuGet.Frameworks": "3.5.0-rc-759",
"NuGet.ProjectModel": "3.5.0-rc-759",
"Microsoft.DotNet.ProjectModel": {
"target": "project"
},
Expand Down

0 comments on commit e64b514

Please sign in to comment.