-Updated build to use .NET CLI

-.NET Standard 1.0 included in package
This commit is contained in:
James Newton-King
2016-05-14 13:43:43 +12:00
parent e31200aead
commit e8f4a3b651
17 changed files with 496 additions and 121 deletions
+44 -12
View File
@@ -1,15 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Newtonsoft.Json</id>
<version></version>
<title>Json.NET</title>
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
<authors>James Newton-King</authors>
<language>en-US</language>
<projectUrl>http://www.newtonsoft.com/json</projectUrl>
<iconUrl>http://www.newtonsoft.com/content/images/nugeticon.png</iconUrl>
<licenseUrl>https://raw.github.com/JamesNK/Newtonsoft.Json/master/LICENSE.md</licenseUrl>
<tags>json</tags>
</metadata>
<metadata>
<id>Newtonsoft.Json</id>
<version></version>
<title>Json.NET</title>
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
<authors>James Newton-King</authors>
<language>en-US</language>
<projectUrl>http://www.newtonsoft.com/json</projectUrl>
<iconUrl>http://www.newtonsoft.com/content/images/nugeticon.png</iconUrl>
<licenseUrl>https://raw.github.com/JamesNK/Newtonsoft.Json/master/LICENSE.md</licenseUrl>
<tags>json</tags>
<dependencies>
<group targetFramework=".NETFramework4.5" />
<group targetFramework=".NETFramework4.0" />
<group targetFramework=".NETFramework3.5" />
<group targetFramework=".NETFramework2.0" />
<group targetFramework=".NETPortable4.5-Profile259" />
<group targetFramework=".NETPortable4.0-Profile328" />
<group targetFramework=".NETStandard1.0">
<dependency id="Microsoft.CSharp" version="4.0.1-rc2-24027" />
<dependency id="System.Collections" version="4.0.11-rc2-24027" />
<dependency id="System.Diagnostics.Debug" version="4.0.11-rc2-24027" />
<dependency id="System.Dynamic.Runtime" version="4.0.11-rc2-24027" />
<dependency id="System.Globalization" version="4.0.11-rc2-24027" />
<dependency id="System.IO" version="4.1.0-rc2-24027" />
<dependency id="System.Linq" version="4.1.0-rc2-24027" />
<dependency id="System.Linq.Expressions" version="4.0.11-rc2-24027" />
<dependency id="System.ObjectModel" version="4.0.12-rc2-24027" />
<dependency id="System.Reflection" version="4.1.0-rc2-24027" />
<dependency id="System.Reflection.Extensions" version="4.0.1-rc2-24027" />
<dependency id="System.Resources.ResourceManager" version="4.0.1-rc2-24027" />
<dependency id="System.Runtime" version="4.1.0-rc2-24027" />
<dependency id="System.Runtime.Extensions" version="4.1.0-rc2-24027" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.1.1-rc2-24027" />
<dependency id="System.Text.Encoding" version="4.0.11-rc2-24027" />
<dependency id="System.Text.Encoding.Extensions" version="4.0.11-rc2-24027" />
<dependency id="System.Text.RegularExpressions" version="4.0.12-rc2-24027" />
<dependency id="System.Threading" version="4.0.11-rc2-24027" />
<dependency id="System.Threading.Tasks" version="4.0.11-rc2-24027" />
<dependency id="System.Xml.ReaderWriter" version="4.0.11-rc2-24027" />
<dependency id="System.Xml.XDocument" version="4.0.11-rc2-24027" />
</group>
</dependencies>
</metadata>
</package>
+30 -26
View File
@@ -1,8 +1,8 @@
properties {
$zipFileName = "Json80r3.zip"
$zipFileName = "Json80r4.zip"
$majorVersion = "8.0"
$majorWithReleaseVersion = "8.0.3"
$nugetPrelease = $null
$majorWithReleaseVersion = "8.0.4"
$nugetPrelease = "beta4"
$version = GetVersion $majorWithReleaseVersion
$packageId = "Newtonsoft.Json"
$signAssemblies = $false
@@ -11,7 +11,7 @@
$buildNuGet = $true
$treatWarningsAsErrors = $false
$workingName = if ($workingName) {$workingName} else {"Working"}
$dnvmVersion = "1.0.0-rc1-update1"
$netCliVersion = "1.0.0-preview1-002702"
$baseDir = resolve-path ..
$buildDir = "$baseDir\Build"
@@ -22,9 +22,9 @@
$workingDir = "$baseDir\$workingName"
$workingSourceDir = "$workingDir\Src"
$builds = @(
@{Name = "Newtonsoft.Json.Dotnet"; TestsName = "Newtonsoft.Json.Tests.Dotnet"; BuildFunction = "DnxBuild"; TestsFunction = "DnxTests"; Constants="dotnet"; FinalDir=$null; NuGetDir = $null; Framework=$null},
@{Name = "Newtonsoft.Json.Dotnet"; TestsName = "Newtonsoft.Json.Tests.Dotnet"; BuildFunction = "NetCliBuild"; TestsFunction = "NetCliTests"; Constants="dotnet"; FinalDir="netstandard1.0"; NuGetDir = "netstandard1.0"; Framework=$null},
@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; BuildFunction = "MSBuildBuild"; TestsFunction = "NUnitTests"; Constants=""; FinalDir="Net45"; NuGetDir = "net45"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; BuildFunction = "MSBuildBuild"; TestsFunction = "NUnitTests"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = "portable-net45+wp80+win8+wpa81+dnxcore50"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; BuildFunction = "MSBuildBuild"; TestsFunction = "NUnitTests"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = "portable-net45+wp80+win8+wpa81"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.Portable40"; TestsName = "Newtonsoft.Json.Tests.Portable40"; BuildFunction = "MSBuildBuild"; TestsFunction = "NUnitTests"; Constants="PORTABLE40"; FinalDir="Portable40"; NuGetDir = "portable-net40+sl5+wp80+win8+wpa81"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.Net40"; TestsName = "Newtonsoft.Json.Tests.Net40"; BuildFunction = "MSBuildBuild"; TestsFunction = "NUnitTests"; Constants="NET40"; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; BuildFunction = "MSBuildBuild"; TestsFunction = "NUnitTests"; Constants="NET35"; FinalDir="Net35"; NuGetDir = "net35"; Framework="net-2.0"},
@@ -90,11 +90,7 @@ task Package -depends Build {
if ($buildNuGet)
{
$nugetVersion = $majorWithReleaseVersion
if ($nugetPrelease -ne $null)
{
$nugetVersion = $nugetVersion + "-" + $nugetPrelease
}
$nugetVersion = GetNuGetVersion
New-Item -Path $workingDir\NuGet -ItemType Directory
@@ -136,6 +132,7 @@ task Package -depends Build {
Write-Host
exec { .\Tools\NuGet\NuGet.exe pack $nuspecPath -Symbols }
exec { dotnet pack $workingSourceDir\Newtonsoft.Json\project.json -c Release }
move -Path .\*.nupkg -Destination $workingDir\NuGet
}
@@ -204,36 +201,30 @@ function MSBuildBuild($build)
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:CopyNuGetImplementations=true" "/p:Platform=Any CPU" "/p:PlatformTarget=AnyCPU" /p:OutputPath=bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$signAssemblies" "/p:TreatWarningsAsErrors=$treatWarningsAsErrors" "/p:VisualStudioVersion=14.0" /p:DefineConstants=`"$constants`" "$workingSourceDir\$name.sln" | Out-Default } "Error building $name"
}
function DnxBuild($build)
function NetCliBuild($build)
{
$name = $build.Name
$projectPath = "$workingSourceDir\Newtonsoft.Json\project.json"
exec { dnvm install $dnvmVersion -r clr | Out-Default }
exec { dnvm use $dnvmVersion -r clr | Out-Default }
exec { .\Tools\Dotnet\install.ps1 -Version $netCliVersion | Out-Default }
Write-Host -ForegroundColor Green "Restoring packages for $name"
Write-Host
exec { dnu restore $projectPath | Out-Default }
exec { dotnet restore $projectPath | Out-Default }
Write-Host -ForegroundColor Green "Building $projectPath"
exec { dnu build $projectPath --configuration Release | Out-Default }
exec { dotnet build $projectPath -f netstandard1.0 -c Release -o bin\Release\netstandard1.0 | Out-Default }
}
function DnxTests($build)
function NetCliTests($build)
{
$name = $build.TestsName
#Write-Host -ForegroundColor Green "Ensuring latest CoreCLR is installed for $name"
#Write-Host
#exec { & $toolsDir\Kvm\kvm.ps1 upgrade -r CoreCLR -NoNative | Out-Default }
exec { dnvm install $dnvmVersion -r coreclr | Out-Default }
exec { dnvm use $dnvmVersion -r coreclr | Out-Default }
exec { .\Tools\Dotnet\install.ps1 -Version $netCliVersion | Out-Default }
Write-Host -ForegroundColor Green "Restoring packages for $name"
Write-Host
exec { dnu restore "$workingSourceDir\Newtonsoft.Json.Tests\project.json" | Out-Default }
exec { dotnet restore "$workingSourceDir\Newtonsoft.Json.Tests\project.json" | Out-Default }
Write-Host -ForegroundColor Green "Ensuring test project builds for $name"
Write-Host
@@ -241,7 +232,7 @@ function DnxTests($build)
try
{
Set-Location "$workingSourceDir\Newtonsoft.Json.Tests"
exec { dnx --configuration Release test | Out-Default }
exec { dotnet test "$workingSourceDir\Newtonsoft.Json.Tests\project.json" -f netcoreapp1.0 -c Release -parallel none | Out-Default }
}
finally
{
@@ -266,6 +257,17 @@ function NUnitTests($build)
exec { .\Tools\NUnit\nunit-console.exe "$workingDir\Deployed\Bin\$finalDir\Newtonsoft.Json.Tests.dll" /framework=$framework /xml:$workingDir\$name.xml | Out-Default } "Error running $name tests"
}
function GetNuGetVersion()
{
$nugetVersion = $majorWithReleaseVersion
if ($nugetPrelease -ne $null)
{
$nugetVersion = $nugetVersion + "-" + $nugetPrelease
}
return $nugetVersion
}
function GetConstants($constants, $includeSigned)
{
$signed = switch($includeSigned) { $true { ";SIGNED" } default { "" } }
@@ -345,9 +347,11 @@ function Update-Project {
$file = switch($sign) { $true { $signKeyPath } default { $null } }
$json = (Get-Content $projectPath) -join "`n" | ConvertFrom-Json
$options = @{"warningsAsErrors" = $true; "keyFile" = $file; "define" = ((GetConstants "dotnet" $sign) -split ";") }
$options = @{"warningsAsErrors" = $true; "xmlDoc" = $true; "keyFile" = $file; "define" = ((GetConstants "dotnet" $sign) -split ";") }
Add-Member -InputObject $json -MemberType NoteProperty -Name "compilationOptions" -Value $options -Force
$json.version = GetNuGetVersion
ConvertTo-Json $json -Depth 10 | Set-Content $projectPath
}
@@ -31,7 +31,9 @@ using System.Security;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
#if PORTABLE40
#if NETSTANDARD10
[assembly: AssemblyTitle("Json.NET Tests .NET Standard 1.0")]
#elif PORTABLE40
[assembly: AssemblyTitle("Json.NET Tests Portable .NET 4.0")]
#elif PORTABLE
[assembly: AssemblyTitle("Json.NET Tests Portable")]
@@ -27,7 +27,7 @@ using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;
#if !(NET20 || NET35 || NETFX_CORE || PORTABLE)
#if !(NET20 || NET35 || NETFX_CORE || PORTABLE || DNXCORE50)
using System.Runtime.Serialization.Json;
#endif
using System.Text;
@@ -5286,7 +5286,7 @@ Path '', line 1, position 1.");
}
#endif
#if !NETFX_CORE
#if !(NETFX_CORE || DNXCORE50)
public class XmlNodeTestObject
{
public XmlDocument Document { get; set; }
@@ -71,7 +71,12 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void GetAttributes_Property()
{
PropertyInfo property = typeof(ReflectionTestObject).GetProperty("TestProperty");
PropertyInfo property;
#if DNXCORE50
property = Newtonsoft.Json.Utilities.TypeExtensions.GetProperty(typeof(ReflectionTestObject), "TestProperty");
#else
property = typeof(ReflectionTestObject).GetProperty("TestProperty");
#endif
ReflectionAttributeProvider provider = new ReflectionAttributeProvider(property);
@@ -85,7 +90,12 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void GetAttributes_Field()
{
FieldInfo field = (FieldInfo)typeof(ReflectionTestObject).GetField("TestField");
FieldInfo field;
#if DNXCORE50
field = (FieldInfo)Newtonsoft.Json.Utilities.TypeExtensions.GetField(typeof(ReflectionTestObject), "TestField");
#else
field = typeof(ReflectionTestObject).GetField("TestField");
#endif
ReflectionAttributeProvider provider = new ReflectionAttributeProvider(field);
@@ -74,11 +74,14 @@ namespace Newtonsoft.Json.Tests.Serialization
var possibleMsgs = new[]
{
"[1] - Error message for member 1 = An item with the same key has already been added.",
"[1] - Error message for member 1 = An element with the same key already exists in the dictionary." // mono
"[1] - Error message for member 1 = An element with the same key already exists in the dictionary.", // mono
"[1] - Error message for member 1 = An item with the same key has already been added. Key: Jim" // netcore
};
VersionKeyedCollection c = JsonConvert.DeserializeObject<VersionKeyedCollection>(json);
Assert.AreEqual(1, c.Count);
Assert.AreEqual(1, c.Messages.Count);
Console.WriteLine(c.Messages[0]);
Assert.IsTrue(possibleMsgs.Any(m => m == c.Messages[0]), "Expected One of: " + Environment.NewLine + string.Join(Environment.NewLine, possibleMsgs) + Environment.NewLine + "Was: " + Environment.NewLine + c.Messages[0]);
}
@@ -41,7 +41,7 @@ using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
#if !(NETFX_CORE || NET20 || NET35)
#if !(NETFX_CORE || NET20 || NET35 || DNXCORE50)
using System.Runtime.Serialization.Json;
#endif
using Newtonsoft.Json.Serialization;
@@ -66,7 +66,11 @@ namespace Newtonsoft.Json.Tests.TestObjects
public override bool CanConvert(Type objectType)
{
#if DNXCORE50
return Newtonsoft.Json.Utilities.TypeExtensions.IsAssignableFrom(typeof(IList<T>), objectType);
#else
return typeof(IList<T>).IsAssignableFrom(objectType);
#endif
}
}
}
+22 -39
View File
@@ -7,11 +7,9 @@
"target": "project"
}
},
"commands": {
"test": "xunit.runner.dnx -parallel none"
},
"testRunner": "xunit",
"frameworks": {
"net45": {
/*"net45": {
"frameworkAssemblies": {
"System.Collections": "",
"System.ComponentModel.DataAnnotations": "",
@@ -38,7 +36,6 @@
},
"net40": {
"frameworkAssemblies": {
"System.Collections": "",
"System.ComponentModel.DataAnnotations": "",
"System.Data": "",
"System.Data.DataSetExtensions": "",
@@ -46,7 +43,6 @@
"System.Data.Linq": "",
"System.Drawing": "",
"System.Numerics": "",
"System.Runtime": "",
"System.Runtime.Serialization": "",
"System.Web": "",
"System.Web.Extensions": "",
@@ -87,40 +83,27 @@
"dependencies": {
"NUnit": "2.6.4"
}
},
"dnxcore50": {
},*/
"netcoreapp1.0": {
"compilationOptions": {
"define": [ "NETSTANDARD10", "DNXCORE50", "PORTABLE" ]
},
"dependencies": {
"Microsoft.CSharp": "4.0.0",
"System.Collections": "4.0.10",
"System.Collections.Immutable": "1.1.37",
"System.ComponentModel.TypeConverter": "4.0.0",
"System.Diagnostics.Debug": "4.0.10",
"System.Dynamic.Runtime": "4.0.10",
"System.Globalization": "4.0.10",
"System.IO": "4.0.10",
"System.Linq": "4.0.0",
"System.Linq.Expressions": "4.0.10",
"System.Reflection.Emit.ILGeneration": "4.0.0",
"System.Reflection.Extensions": "4.0.0",
"System.Reflection.TypeExtensions": "4.0.0",
"System.Runtime": "4.0.20",
"System.Runtime.Extensions": "4.0.10",
"System.Runtime.Numerics": "4.0.0",
"System.Runtime.Serialization.Json": "4.0.0",
"System.Runtime.Serialization.Primitives": "4.0.10",
"System.Runtime.Serialization.Xml": "4.0.10",
"System.Text.Encoding": "4.0.10",
"System.Text.Encoding.CodePages": "4.0.0",
"System.Text.Encoding.Extensions": "4.0.10",
"System.Text.RegularExpressions": "4.0.10",
"System.Threading": "4.0.10",
"System.Xml.ReaderWriter": "4.0.10",
"System.Xml.XDocument": "4.0.10",
"System.Xml.XmlDocument": "4.0.0",
"System.Xml.XmlSerializer": "4.0.10",
"xunit": "2.1.0-*",
"xunit.runner.dnx": "2.1.0-rc1-build204"
}
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-24027"
},
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
"System.Xml.XmlSerializer": "4.0.11-rc2-24027",
"System.Runtime.Serialization.Json": "4.0.2-rc2-24027",
"System.Runtime.Serialization.Xml": "4.1.1-rc2-24027",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-173361-36"
},
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
}
}
@@ -32,7 +32,9 @@ using System.Security;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
#if PORTABLE40
#if NETSTANDARD10
[assembly: AssemblyTitle("Json.NET .NET Standard 1.0")]
#elif PORTABLE40
[assembly: AssemblyTitle("Json.NET Portable .NET 4.0")]
#elif PORTABLE
[assembly: AssemblyTitle("Json.NET Portable")]
@@ -48,7 +50,6 @@ using System.Security;
[assembly: AssemblyTitle("Json.NET .NET 4.0")]
[assembly: AllowPartiallyTrustedCallers]
#else
[assembly: AssemblyTitle("Json.NET")]
[assembly: AllowPartiallyTrustedCallers]
#endif
@@ -40,7 +40,6 @@ using System.Runtime.Serialization;
#if !(DOTNET || PORTABLE || PORTABLE40)
using System.Security.Permissions;
#endif
using System.Xml.Serialization;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Linq;
+28 -26
View File
@@ -1,5 +1,5 @@
{
"version": "7.0.2-beta1",
"version": "1.0.0-*",
"title": "Json.NET",
"description": "Json.NET is a popular high-performance JSON framework for .NET",
"authors": [ "James Newton-King" ],
@@ -61,6 +61,7 @@
"System.ObjectModel": "",
"System.Reflection": "",
"System.Reflection.Extensions": "",
"System.Resources.ResourceManager": "",
"System.Runtime": "",
"System.Runtime.Extensions": "",
"System.Runtime.Serialization": "",
@@ -88,32 +89,33 @@
"System.Xml": ""
}
},
"dotnet": {
"netstandard1.0": {
"compilationOptions": {
"define": [ "NETSTANDARD10", "PORTABLE" ]
},
"dependencies": {
"Microsoft.CSharp": "4.0.0",
"System.Collections": "4.0.10",
"System.Collections.Concurrent": "4.0.10",
"System.ComponentModel.TypeConverter": "4.0.0",
"System.Diagnostics.Debug": "4.0.10",
"System.Dynamic.Runtime": "4.0.10",
"System.Globalization": "4.0.10",
"System.IO": "4.0.10",
"System.Linq": "4.0.0",
"System.Linq.Expressions": "4.0.10",
"System.ObjectModel": "4.0.10",
"System.Reflection": "4.0.10",
"System.Reflection.Extensions": "4.0.0",
"System.Runtime": "4.0.20",
"System.Runtime.Extensions": "4.0.10",
"System.Runtime.Numerics": "4.0.0",
"System.Runtime.Serialization.Primitives": "4.0.10",
"System.Text.Encoding": "4.0.10",
"System.Text.Encoding.Extensions": "4.0.10",
"System.Text.RegularExpressions": "4.0.10",
"System.Threading": "4.0.10",
"System.Threading.Tasks": "4.0.10",
"System.Xml.ReaderWriter": "4.0.10",
"System.Xml.XDocument": "4.0.10"
"Microsoft.CSharp": "4.0.1-rc2-24027",
"System.Collections": "4.0.11-rc2-24027",
"System.Diagnostics.Debug": "4.0.11-rc2-24027",
"System.Dynamic.Runtime": "4.0.11-rc2-24027",
"System.Globalization": "4.0.11-rc2-24027",
"System.IO": "4.1.0-rc2-24027",
"System.Linq": "4.1.0-rc2-24027",
"System.Linq.Expressions": "4.0.11-rc2-24027",
"System.ObjectModel": "4.0.12-rc2-24027",
"System.Reflection": "4.1.0-rc2-24027",
"System.Reflection.Extensions": "4.0.1-rc2-24027",
"System.Resources.ResourceManager": "4.0.1-rc2-24027",
"System.Runtime": "4.1.0-rc2-24027",
"System.Runtime.Extensions": "4.1.0-rc2-24027",
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
"System.Text.Encoding": "4.0.11-rc2-24027",
"System.Text.Encoding.Extensions": "4.0.11-rc2-24027",
"System.Text.RegularExpressions": "4.0.12-rc2-24027",
"System.Threading": "4.0.11-rc2-24027",
"System.Threading.Tasks": "4.0.11-rc2-24027",
"System.Xml.ReaderWriter": "4.0.11-rc2-24027",
"System.Xml.XDocument": "4.0.11-rc2-24027"
}
}
}
+3 -3
View File
@@ -3,8 +3,8 @@
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="AspNet VNext (CI Builds)" value="https://www.myget.org/F/aspnetvnext/api/v2" />
<add key="xunit (CI Builds)" value="https://www.myget.org/F/xunit/api/v2" />
<add key="NuGet.org (v2)" value="https://www.nuget.org/api/v2" />
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
<add key="NuGet.org (v3)" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
+2 -5
View File
@@ -1,6 +1,3 @@
{
"projects": [ "src" ],
"sdk": {
"version": "1.0.0-rc1-update1"
}
}
"projects": [ "src" ]
}
+338
View File
@@ -0,0 +1,338 @@
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
<#
.SYNOPSIS
Installs dotnet cli
.DESCRIPTION
Installs dotnet cli. If dotnet installation already exists in the given directory
it will update it only if the requested version differs from the one already installed.
.PARAMETER Channel
Default: preview
Channel is the way of reasoning about stability and quality of dotnet. This parameter takes one of the values:
- future - Possibly unstable, frequently changing, may contain new finished and unfinished features
- preview - Pre-release stable with known issues and feature gaps
- production - Most stable releases
.PARAMETER Version
Default: latest
Represents a build version on specific channel. Possible values:
- 4-part version in a format A.B.C.D - represents specific version of build
- latest - most latest build on specific channel
- lkg - last known good version on specific channel
Note: LKG work is in progress. Once the work is finished, this will become new default
.PARAMETER InstallDir
Default: %LocalAppData%\Microsoft\dotnet
Path to where to install dotnet. Note that binaries will be placed directly in a given directory.
.PARAMETER Architecture
Default: <auto> - this value represents currently running OS architecture
Architecture of dotnet binaries to be installed.
Possible values are: <auto>, x64 and x86
.PARAMETER DebugSymbols
If set the installer will include symbols in the installation.
.PARAMETER DryRun
If set it will not perform installation but instead display what command line to use to consistently install
currently requested version of dotnet cli. In example if you specify version 'latest' it will display a link
with specific version so that this command can be used deterministicly in a build script.
It also displays binaries location if you prefer to install or download it yourself.
.PARAMETER NoPath
By default this script will set environment variable PATH for the current process to the binaries folder inside installation folder.
If set it will display binaries location but not set any environment variable.
.PARAMETER Verbose
Displays diagnostics information.
.PARAMETER AzureFeed
Default: https://dotnetcli.blob.core.windows.net/dotnet
This parameter should not be usually changed by user. It allows to change URL for the Azure feed used by this installer.
#>
[cmdletbinding()]
param(
[string]$Channel="preview",
[string]$Version="Latest",
[string]$InstallDir="<auto>",
[string]$Architecture="<auto>",
[switch]$DebugSymbols, # TODO: Switch does not work yet. Symbols zip is not being uploaded yet.
[switch]$DryRun,
[switch]$NoPath,
[string]$AzureFeed="https://dotnetcli.blob.core.windows.net/dotnet"
)
Set-StrictMode -Version Latest
$ErrorActionPreference="Stop"
$ProgressPreference="SilentlyContinue"
$BinFolderRelativePath=""
# example path with regex: shared/1.0.0-beta-12345/somepath
$VersionRegEx="/\d+\.\d+[^/]+/"
$OverrideNonVersionedFiles=$true
function Say($str) {
Write-Host "dotnet_install: $str"
}
function Say-Verbose($str) {
Write-Verbose "dotnet_install: $str"
}
function Say-Invocation($Invocation) {
$command = $Invocation.MyCommand;
$args = (($Invocation.BoundParameters.Keys | foreach { "-$_ `"$($Invocation.BoundParameters[$_])`"" }) -join " ")
Say-Verbose "$command $args"
}
function Get-Machine-Architecture() {
Say-Invocation $MyInvocation
# possible values: AMD64, IA64, x86
return $ENV:PROCESSOR_ARCHITECTURE
}
# TODO: Architecture and CLIArchitecture should be unified
function Get-CLIArchitecture-From-Architecture([string]$Architecture) {
Say-Invocation $MyInvocation
switch ($Architecture.ToLower()) {
{ $_ -eq "<auto>" } { return Get-CLIArchitecture-From-Architecture $(Get-Machine-Architecture) }
{ ($_ -eq "amd64") -or ($_ -eq "x64") } { return "x64" }
{ $_ -eq "x86" } { return "x86" }
default { throw "Architecture not supported. If you think this is a bug, please report it at https://github.com/dotnet/cli/issues" }
}
}
function Get-Version-Info-From-Version-Text([string]$VersionText) {
Say-Invocation $MyInvocation
$Data = @($VersionText.Split([char[]]@(), [StringSplitOptions]::RemoveEmptyEntries));
$VersionInfo = @{}
$VersionInfo.CommitHash = $Data[0].Trim()
$VersionInfo.Version = $Data[1].Trim()
return $VersionInfo
}
function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [string]$CLIArchitecture) {
Say-Invocation $MyInvocation
$VersionFileUrl = "$AzureFeed/$AzureChannel/dnvm/latest.win.$CLIArchitecture.version"
$Response = Invoke-WebRequest -UseBasicParsing $VersionFileUrl
$VersionText = [Text.Encoding]::UTF8.GetString($Response.Content)
$VersionInfo = Get-Version-Info-From-Version-Text $VersionText
return $VersionInfo
}
# TODO: AzureChannel and Channel should be unified
function Get-Azure-Channel-From-Channel([string]$Channel) {
Say-Invocation $MyInvocation
# For compatibility with build scripts accept also directly Azure channels names
switch ($Channel.ToLower()) {
{ ($_ -eq "future") -or ($_ -eq "dev") } { return "dev" }
{ ($_ -eq "preview") -or ($_ -eq "beta") } { return "beta" }
{ $_ -eq "production" } { throw "Production channel does not exist yet" }
default { throw "``$Channel`` is an invalid channel name. Use one of the following: ``future``, ``preview``, ``production``" }
}
}
function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$AzureChannel, [string]$CLIArchitecture, [string]$Version) {
Say-Invocation $MyInvocation
switch ($Version.ToLower()) {
{ $_ -eq "latest" } {
$LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -AzureChannel $AzureChannel -CLIArchitecture $CLIArchitecture
return $LatestVersionInfo.Version
}
{ $_ -eq "lkg" } { throw "``-Version LKG`` not supported yet." }
default { return $Version }
}
}
function Get-Download-Links([string]$AzureFeed, [string]$AzureChannel, [string]$SpecificVersion, [string]$CLIArchitecture) {
Say-Invocation $MyInvocation
$ret = @()
$files = @("dotnet-dev")
foreach ($file in $files) {
$PayloadURL = "$AzureFeed/$AzureChannel/Binaries/$SpecificVersion/$file-win-$CLIArchitecture.$SpecificVersion.zip"
Say-Verbose "Constructed payload URL: $PayloadURL"
$ret += $PayloadURL
}
return $ret
}
function Get-User-Share-Path() {
Say-Invocation $MyInvocation
$InstallRoot = $env:DOTNET_INSTALL_DIR
if (!$InstallRoot) {
$InstallRoot = "$env:LocalAppData\Microsoft\dotnet"
}
return $InstallRoot
}
function Resolve-Installation-Path([string]$InstallDir) {
Say-Invocation $MyInvocation
if ($InstallDir -eq "<auto>") {
return Get-User-Share-Path
}
return $InstallDir
}
function Get-Version-Info-From-Version-File([string]$InstallRoot, [string]$RelativePathToVersionFile) {
Say-Invocation $MyInvocation
$VersionFile = Join-Path -Path $InstallRoot -ChildPath $RelativePathToVersionFile
Say-Verbose "Local version file: $VersionFile"
if (Test-Path $VersionFile) {
$VersionText = cat $VersionFile
Say-Verbose "Local version file text: $VersionText"
return Get-Version-Info-From-Version-Text $VersionText
}
Say-Verbose "Local version file not found."
return $null
}
function Is-Dotnet-Package-Installed([string]$InstallRoot, [string]$RelativePathToPackage, [string]$SpecificVersion) {
Say-Invocation $MyInvocation
$DotnetPackagePath = Join-Path -Path $InstallRoot -ChildPath $RelativePathToPackage | Join-Path -ChildPath $SpecificVersion
Say-Verbose "Is-Dotnet-Package-Installed: Path to a package: $DotnetPackagePath"
return Test-Path $DotnetPackagePath -PathType Container
}
function Get-Absolute-Path([string]$RelativeOrAbsolutePath) {
# Too much spam
# Say-Invocation $MyInvocation
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($RelativeOrAbsolutePath)
}
function Get-Path-Prefix-With-Version($path) {
$match = [regex]::match($path, $VersionRegEx)
if ($match.Success) {
return $entry.FullName.Substring(0, $match.Index + $match.Length)
}
return $null
}
function Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package([System.IO.Compression.ZipArchive]$Zip, [string]$OutPath) {
Say-Invocation $MyInvocation
$ret = @()
foreach ($entry in $Zip.Entries) {
$dir = Get-Path-Prefix-With-Version $entry.FullName
if ($dir -ne $null) {
$path = Get-Absolute-Path $(Join-Path -Path $OutPath -ChildPath $dir)
if (-Not (Test-Path $path -PathType Container)) {
$ret += $dir
}
}
}
$ret = $ret | Sort-Object | Get-Unique
$values = ($ret | foreach { "$_" }) -join ";"
Say-Verbose "Directories to unpack: $values"
return $ret
}
# Example zip content and extraction algorithm:
# Rule: files if extracted are always being extracted to the same relative path locally
# .\
# a.exe # file does not exist locally, extract
# b.dll # file exists locally, override only if $OverrideFiles set
# aaa\ # same rules as for files
# ...
# abc\1.0.0\ # directory contains version and exists locally
# ... # do not extract content under versioned part
# abc\asd\ # same rules as for files
# ...
# def\ghi\1.0.1\ # directory contains version and does not exist locally
# ... # extract content
function Extract-Dotnet-Package([string]$ZipPath, [string]$OutPath) {
Say-Invocation $MyInvocation
Add-Type -Assembly System.IO.Compression.FileSystem | Out-Null
Set-Variable -Name Zip
try {
$Zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath)
$DirectoriesToUnpack = Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package -Zip $Zip -OutPath $OutPath
foreach ($entry in $Zip.Entries) {
$PathWithVersion = Get-Path-Prefix-With-Version $entry.FullName
if (($PathWithVersion -eq $null) -Or ($DirectoriesToUnpack -contains $PathWithVersion)) {
$DestinationPath = Get-Absolute-Path $(Join-Path -Path $OutPath -ChildPath $entry.FullName)
$DestinationDir = Split-Path -Parent $DestinationPath
$OverrideFiles=$OverrideNonVersionedFiles -Or (-Not (Test-Path $DestinationPath))
if ((-Not $DestinationPath.EndsWith("\")) -And $OverrideFiles) {
New-Item -ItemType Directory -Force -Path $DestinationDir | Out-Null
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $DestinationPath, $OverrideNonVersionedFiles)
}
}
}
}
finally {
if ($Zip -ne $null) {
$Zip.Dispose()
}
}
}
$AzureChannel = Get-Azure-Channel-From-Channel -Channel $Channel
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -AzureChannel $AzureChannel -CLIArchitecture $CLIArchitecture -Version $Version
$DownloadLinks = Get-Download-Links -AzureFeed $AzureFeed -AzureChannel $AzureChannel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
if ($DryRun) {
Say "Payload URLs:"
foreach ($DownloadLink in $DownloadLinks) {
Say "- $DownloadLink"
}
Say "Repeatable invocation: .\$($MyInvocation.MyCommand) -Version $SpecificVersion -Channel $Channel -Architecture $CLIArchitecture -InstallDir $InstallDir"
return
}
$InstallRoot = Resolve-Installation-Path $InstallDir
Say-Verbose "InstallRoot: $InstallRoot"
$IsSdkInstalled = Is-Dotnet-Package-Installed -InstallRoot $InstallRoot -RelativePathToPackage "sdk" -SpecificVersion $SpecificVersion
Say-Verbose ".NET SDK installed? $IsSdkInstalled"
if ($IsSdkInstalled) {
Say ".NET SDK version $SpecificVersion is already installed."
return
}
New-Item -ItemType Directory -Force -Path $InstallRoot | Out-Null
foreach ($DownloadLink in $DownloadLinks) {
$ZipPath = [System.IO.Path]::GetTempFileName()
Say "Downloading $DownloadLink"
$resp = Invoke-WebRequest -UseBasicParsing $DownloadLink -OutFile $ZipPath
Say "Extracting zip from $DownloadLink"
Extract-Dotnet-Package -ZipPath $ZipPath -OutPath $InstallRoot
Remove-Item $ZipPath
}
$BinPath = Get-Absolute-Path $(Join-Path -Path $InstallRoot -ChildPath $BinFolderRelativePath)
if (-Not $NoPath) {
Say "Adding to current process PATH: `"$BinPath`". Note: This change will not be visible if PowerShell was run as a child process."
$env:path += ";$BinPath"
}
else {
Say "Binaries of dotnet can be found in $BinPath"
}
Say "Installation finished"
Binary file not shown.