提交 68bf8bce 编写于 作者: M Matt Ellis

Support building nupkgs on *NIX

For the set of assemblies we build on *NIX, we should also be able to
build the coresponding nupkgs so they can be used by other repositories.
上级 f04d6b2e
......@@ -17,7 +17,8 @@
"Microsoft.NETCore.TestHost": "1.1.0",
"Microsoft.NETCore.App": "1.1.0",
"Microsoft.Portable.Targets": "0.1.1-dev",
"Newtonsoft.Json": "8.0.3"
"Newtonsoft.Json": "8.0.3",
"NuGet.CommandLine.XPlat": "3.5.0-beta2-1484"
},
"frameworks": {
"NETCoreApp1.1": {
......
#r "System.Xml.Linq"
#r "System.Xml.XDocument.dll"
using System;
using System.Collections.Generic;
using System.Diagnostics;
......@@ -17,7 +17,8 @@ if (Args.Count() != 3)
Environment.Exit(1);
}
var SolutionRoot = Path.GetFullPath(Path.Combine(ScriptRoot(), "../../"));
var SolutionRoot = Path.GetFullPath(Path.Combine(ScriptRoot(), "..", ".."));
var ToolsetPath = Path.Combine(SolutionRoot, "Binaries", "toolset");
string ScriptRoot([CallerFilePath]string path = "") => Path.GetDirectoryName(path);
......@@ -69,6 +70,8 @@ string GetExistingPackageVersion(string name)
return null;
}
var IsCoreBuild = Directory.Exists(ToolsetPath);
#endregion
var NuGetAdditionalFilesPath = Path.Combine(SolutionRoot, "build/NuGetAdditionalFiles");
......@@ -77,7 +80,7 @@ var NetCompilersPropsPath = Path.Combine(NuGetAdditionalFilesPath, "Microsoft.Ne
string[] RedistPackageNames = {
"Microsoft.CodeAnalysis",
"Microsoft.Codeanalysis.Build.Tasks",
"Microsoft.CodeAnalysis.Build.Tasks",
"Microsoft.CodeAnalysis.Common",
"Microsoft.CodeAnalysis.Compilers",
"Microsoft.CodeAnalysis.CSharp.Features",
......@@ -126,6 +129,24 @@ var PreReleaseOnlyPackages = new HashSet<string>
"Microsoft.VisualStudio.LanguageServices.Next",
};
// The assets for these packages are not produced when building on Unix
// and we don't want to attempt to package them when building packages.
var PackagesNotBuiltOnCore = new HashSet<string>
{
"Microsoft.CodeAnalysis.CSharp.Features",
"Microsoft.CodeAnalysis.EditorFeatures",
"Microsoft.CodeAnalysis.EditorFeatures.Text",
"Microsoft.CodeAnalysis.Features",
"Microsoft.CodeAnalysis.Remote.ServiceHub",
"Microsoft.CodeAnalysis.Remote.Workspaces",
"Microsoft.CodeAnalysis.VisualBasic.Features",
"Microsoft.CodeAnalysis.Workspaces.Common",
"Microsoft.Net.Compilers",
"Microsoft.VisualStudio.LanguageServices",
"Microsoft.VisualStudio.LanguageServices.Next",
"Roslyn.VisualStudio.Test.Utilities",
};
// Create an empty directory to be used in NuGet pack
var emptyDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var dirInfo = Directory.CreateDirectory(emptyDir);
......@@ -145,32 +166,58 @@ void ReportError(string message)
int PackFiles(string[] nuspecFiles, string licenseUrl)
{
string commonArgs =
$"-BasePath \"{BinDir}\" " +
var commonProperties = new Dictionary<string, string>()
{
{ "licenseUrl", licenseUrl },
{ "version", BuildVersion },
{ "authors", Authors },
{ "projectURL", ProjectURL },
{ "tags", Tags },
{ "thirdPartyNoticesPath", ThirdPartyNoticesPath },
{ "netCompilersPropsPath", NetCompilersPropsPath },
{ "emptyDirPath", emptyDir },
};
foreach (var dependencyVersion in dependencyVersions)
{
commonProperties[dependencyVersion.VariableName] = dependencyVersion.Value;
}
string commonArgs;
if (!IsCoreBuild)
{
commonArgs = $"-BasePath \"{BinDir}\" " +
$"-OutputDirectory \"{OutDir}\" " +
$"-prop licenseUrl=\"{licenseUrl}\" " +
$"-prop version=\"{BuildVersion}\" " +
$"-prop authors={Authors} " +
$"-prop projectURL=\"{ProjectURL}\" " +
$"-prop tags=\"{Tags}\" " +
$"-prop thirdPartyNoticesPath=\"{ThirdPartyNoticesPath}\" " +
$"-prop netCompilersPropsPath=\"{NetCompilersPropsPath}\" " +
$"-prop emptyDirPath=\"{emptyDir}\" " +
string.Join(" ", dependencyVersions.Select(d => $"-prop {d.VariableName}=\"{d.Value}\""));
string.Join(" ", commonProperties.Select(p => $"-prop {p.Key}=\"{p.Value}\""));
}
else
{
commonArgs = $"--base-path \"{BinDir}\" " +
$"--output-directory \"{OutDir}\" " +
$"--properties \"{string.Join(";", commonProperties.Select(p => $"{p.Key}={p.Value}"))}\"";
}
int exit = 0;
foreach (var file in nuspecFiles)
{
var nugetArgs = $@"pack {file} {commonArgs}";
var nugetExePath = Path.GetFullPath(Path.Combine(SolutionRoot, "nuget.exe"));
var p = new Process();
p.StartInfo.FileName = nugetExePath;
p.StartInfo.Arguments = nugetArgs;
if (!IsCoreBuild)
{
p.StartInfo.FileName = Path.GetFullPath(Path.Combine(SolutionRoot, "nuget.exe"));
p.StartInfo.Arguments = $@"pack {file} {commonArgs}";
}
else
{
p.StartInfo.FileName = Path.Combine(ToolsetPath, "corerun");
p.StartInfo.Arguments = $@"{Path.Combine(ToolsetPath, "NuGet.CommandLine.XPlat.dll")} pack {file} {commonArgs}";
}
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
Console.WriteLine($"{Environment.NewLine}Running: nuget.exe {nugetArgs}");
Console.WriteLine($"{Environment.NewLine}Running: nuget pack {file} {commonArgs}");
p.Start();
p.WaitForExit();
......@@ -182,7 +229,7 @@ int PackFiles(string[] nuspecFiles, string licenseUrl)
string message;
if (BuildingReleaseNugets && stdErr.Contains("A stable release of a package should not have a prerelease dependency."))
{
// If we are building release nugets and if any packages have dependencies on prerelease packages
// If we are building release nugets and if any packages have dependencies on prerelease packages
// then we want to ignore the error and allow the build to succeed.
currentExit = 0;
message = $"{file}: {stdErr}";
......@@ -218,7 +265,10 @@ IEnumerable<XElement> MakeRoslynPackageElements(string[] roslynPackageNames)
void GeneratePublishingConfig(string fileName, IEnumerable<XElement> packages)
{
var doc = new XDocument(new XElement("packages", packages.ToArray()));
doc.Save(Path.Combine(OutDir, fileName));
using (FileStream fs = File.OpenWrite(Path.Combine(OutDir, fileName)))
{
doc.Save(fs);
}
}
void GeneratePublishingConfig(string[] roslynPackageNames)
......@@ -236,9 +286,21 @@ void GeneratePublishingConfig(string[] roslynPackageNames)
}
}
string[] GetRoslynPackageNames(string[] packageNames)
string[] GetRoslynPackageNames(string[] packages)
{
return (BuildingReleaseNugets) ? packageNames.Where(pn => !PreReleaseOnlyPackages.Contains(pn)).ToArray() : packageNames;
IEnumerable<string> packageNames = packages;
if (BuildingReleaseNugets)
{
packageNames = packageNames.Where(pn => !PreReleaseOnlyPackages.Contains(pn));
}
if (IsCoreBuild)
{
packageNames = packageNames.Where(pn => !PackagesNotBuiltOnCore.Contains(pn));
}
return packageNames.ToArray();
}
int DoWork(string[] packageNames, string licenseUrl)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册