Upgrade dotnet-publish-iis to Microsoft.NETCore.App 1.1 and add dotnet-cli package type

This commit is contained in:
Nate McMaster 2016-10-18 16:04:32 -07:00
parent 062a44e032
commit ca1341144a
9 changed files with 285 additions and 6 deletions

4
.gitignore vendored
View File

@ -27,4 +27,6 @@ project.lock.json
*.ipch
*.vs/
.testPublish/
.build/
.build/
*.nuget.props
*.nuget.targets

View File

@ -5,7 +5,9 @@
],
"packages": {
"Microsoft.AspNetCore.Server.IISIntegration": { },
"Microsoft.AspNetCore.Server.IISIntegration.Tools": { }
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"packageTypes": ["DotnetCliTool"]
}
}
},
"Default": { // Rules to run for packages not listed in any other set.

View File

@ -1,3 +1,7 @@
use namespace="System.IO"
default BASE_DIR_LOCAL='${Directory.GetCurrentDirectory()}'
default BUILD_DIR_LOCAL='${Path.Combine(BASE_DIR_LOCAL, "artifacts", "build")}'
var VERSION='0.1'
var FULL_VERSION='0.1'
@ -5,3 +9,21 @@ var AUTHORS='Microsoft Open Technologies, Inc.'
use-standard-lifecycle
k-standard-goals
#build-pack .build-compile target='compile'
@{
if (Directory.Exists("src") && !IsLinux)
{
Directory.CreateDirectory(BUILD_DIR_LOCAL);
Dotnet("run -p tools/NuGetPackager -- -c " + E("Configuration") +
" -o artifacts/build/ "+
"-n src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Microsoft.AspNetCore.Server.IISIntegration.Tools.nuspec");
DotnetPack("src/Microsoft.AspNetCore.Server.IISIntegration/project.json", BUILD_DIR_LOCAL, E("Configuration"), E("KOREBUILD_DOTNET_PACK_OPTIONS") + " --no-build");
foreach (var nupkg in Files.Include(Path.Combine(BUILD_DIR_LOCAL, "*/" + E("Configuration") + "/*.nupkg")))
{
File.Copy(nupkg, Path.Combine(BUILD_DIR_LOCAL, Path.GetFileName(nupkg)), true);
}
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Microsoft.AspNetCore.Server.IISIntegration.Tools</id>
<version>$version$</version>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>IIS Integration publish tool for .NET Core CLI. Contains the dotnet-publish-iis command for publishing web applications to be hosted using IIS.</description>
<tags>aspnetcore,iis</tags>
<serviceable>true</serviceable>
<packageTypes>
<packageType name="DotnetCliTool" />
</packageTypes>
<dependencies>
<group targetFramework=".NETCoreApp1.0">
<dependency id="Microsoft.DotNet.ProjectModel" version="$dep_1$" />
<dependency id="Microsoft.Extensions.CommandLineUtils" version="$dep_2$" />
<dependency id="Microsoft.NETCore.App" version="$dep_3$" />
<dependency id="System.Diagnostics.Process" version="$dep_4$" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin/$configuration$/netcoreapp1.0/dotnet-publish-iis.dll" target="lib\netcoreapp1.0\" />
<file src="bin/$configuration$/netcoreapp1.0/dotnet-publish-iis.xml" target="lib\netcoreapp1.0\" />
<file src="bin/$configuration$/netcoreapp1.0/dotnet-publish-iis.runtimeconfig.json" target="lib\netcoreapp1.0\" />
</files>
</package>

View File

@ -24,14 +24,14 @@
"dependencies": {
"Microsoft.Extensions.CommandLineUtils": "1.1.0-*",
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"System.Diagnostics.Process": "4.1.0-*"
"System.Diagnostics.Process": "4.3.0-*"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-*"
"version": "1.1.0-*"
}
}
}

View File

@ -5,11 +5,11 @@
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-*"
},
"frameworks": {
"netcoreapp1.0": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-*"
"version": "1.1.0-*"
}
}
}

View File

@ -0,0 +1,150 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Utilities;
using NuGet.Frameworks;
using NuGet.Versioning;
namespace NuGetPackager
{
internal class PackCommand
{
private readonly string _baseDir;
public PackCommand(string baseDir)
{
_baseDir = baseDir;
}
public async Task PackAsync(string nuspec, string config, string outputDir)
{
var project = ProjectContext.Create(Path.GetDirectoryName(nuspec), FrameworkConstants.CommonFrameworks.NetCoreApp10);
var props = "configuration=" + config;
var idx = 0;
foreach (var depVersion in GetDependencies(project).OrderBy(p => p.Item1).Select(p => p.Item2))
{
props += $";dep_{++idx}={depVersion}";
}
var buildCommand = Command.CreateDotNet("build",
new[] { project.ProjectFile.ProjectFilePath, "--configuration", config },
configuration: config);
if (buildCommand.Execute().ExitCode != 0)
{
throw new GracefulException("Build failed");
}
Directory.CreateDirectory(outputDir);
var version = project.ProjectFile.Version.ToNormalizedString();
await Nuget("pack",
nuspec,
"-Verbosity", "detailed",
"-OutputDirectory", outputDir,
"-Version", version,
"-Properties", props);
}
private IEnumerable<Tuple<string, string>> GetDependencies(ProjectContext context)
{
// copied from https://github.com/dotnet/cli/blob/da0e365264e0ab555cdde978bdfd2e504bada49a/src/dotnet/commands/dotnet-pack/PackageGenerator.cs
var project = context.RootProject;
foreach (var dependency in project.Dependencies)
{
if (dependency.Type.Equals(LibraryDependencyType.Build))
{
continue;
}
// TODO: Efficiency
var dependencyDescription = context.LibraryManager.GetLibraries().First(l => l.RequestedRanges.Contains(dependency));
// REVIEW: Can we get this far with unresolved dependencies
if (!dependencyDescription.Resolved)
{
continue;
}
if (dependencyDescription.Identity.Type == LibraryType.Project &&
((ProjectDescription)dependencyDescription).Project.EmbedInteropTypes)
{
continue;
}
VersionRange dependencyVersion = null;
if (dependency.VersionRange == null ||
dependency.VersionRange.IsFloating)
{
dependencyVersion = new VersionRange(dependencyDescription.Identity.Version);
}
else
{
dependencyVersion = dependency.VersionRange;
}
Reporter.Verbose.WriteLine($"Adding dependency {dependency.Name.Yellow()} {VersionUtility.RenderVersion(dependencyVersion).Yellow()}");
yield return new Tuple<string, string>(dependency.Name, dependencyVersion.MinVersion.ToString());
}
}
private static string GetLockFileVersion(ProjectContext project, string name) =>
project
.LockFile
.PackageLibraries
.First(l => l.Name.Equals(name))
.Version
.ToNormalizedString();
private async Task Nuget(params string[] args)
{
var pInfo = new ProcessStartInfo
{
Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args),
FileName = await GetNugetExePath()
};
Console.WriteLine("command: ".Bold().Blue() + pInfo.FileName);
Console.WriteLine("arguments: ".Bold().Blue() + pInfo.Arguments);
Process.Start(pInfo).WaitForExit();
}
private async Task<string> GetNugetExePath()
{
if (Environment.GetEnvironmentVariable("KOREBUILD_NUGET_EXE") != null)
{
return Environment.GetEnvironmentVariable("KOREBUILD_NUGET_EXE");
}
var nugetPath = Path.Combine(_baseDir, ".build", "nuget.3.5.0-rc1.exe");
if (File.Exists(nugetPath))
{
return nugetPath;
}
Console.WriteLine("log : Downloading nuget.exe 3.5.0-rc1".Bold().Black());
var response = await new HttpClient().GetAsync("https://dist.nuget.org/win-x86-commandline/v3.5.0-rc1/NuGet.exe");
using (var file = new FileStream(nugetPath, FileMode.CreateNew))
{
response.EnsureSuccessStatusCode();
await response.Content.LoadIntoBufferAsync();
await response.Content.CopyToAsync(file);
}
return nugetPath;
}
}
}

View File

@ -0,0 +1,55 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Linq;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.DotNet.Cli.Utils;
namespace NuGetPackager
{
/// <summary>
/// This replaces the "dotnet-pack" command, which doesn't not yet support "package types"
/// and probably won't in time for the next release.
/// TODO remove this once CLI supports package type
/// </summary>
public class Program
{
public static int Main(string[] args)
{
var app = new CommandLineApplication();
var optOutput = app.Option("-o|--output-dir <dir>", "Output dir", CommandOptionType.SingleValue);
var optConfig = app.Option("-c|--configuration <configuration>", "Config", CommandOptionType.SingleValue);
var optsNuspec = app.Option("-n|--nuspec <nuspec>", "nuspec", CommandOptionType.MultipleValue);
app.OnExecute(async () =>
{
if (!optsNuspec.Values.Any())
{
Reporter.Error.WriteLine("Missing values for --nuspec");
return 1;
}
var config = optConfig.HasValue()
? optConfig.Value()
: "Debug";
var output = optOutput.Value() ?? Directory.GetCurrentDirectory();
if (!Path.IsPathRooted(output))
{
output = Path.Combine(Directory.GetCurrentDirectory(), output);
}
var packer = new PackCommand(Directory.GetCurrentDirectory());
foreach (var nuspec in optsNuspec.Values)
{
await packer.PackAsync(nuspec, config, output);
}
return 0;
});
return app.Execute(args);
}
}
}

View File

@ -0,0 +1,19 @@
{
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0-*"
},
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
"Microsoft.Extensions.CommandLineUtils": "1.1.0-*"
},
"frameworks": {
"netcoreapp1.1": { }
}
}