Update readme, add linux md, move samples to folders for each version of DNX.
This commit is contained in:
parent
514d9d7eef
commit
f37488fa3b
|
|
@ -0,0 +1,114 @@
|
|||
> Tested on: Ubuntu 14.04, Mint 17.01
|
||||
|
||||
As with all other operating systems you need DNVM to get going with ASP.NEt 5. To get it you run curl to download a .sh file and then run it. However, getting a new Linux machine configured to be able to actually run an ASP.NET 5 application is more complicated.
|
||||
|
||||
To setup our Linux machine we will:
|
||||
|
||||
* Get a working version of Mono
|
||||
* Get and compile libuv (Required for the Kestrel server)
|
||||
* Get DNVM
|
||||
* Add sources to NuGet.config (For package restore)
|
||||
|
||||
###Docker
|
||||
|
||||
There are instructions on how to use the ASP.NET [Docker](https://www.docker.com/) image here: http://blogs.msdn.com/b/webdev/archive/2015/01/14/running-asp-net-5-applications-in-linux-containers-with-docker.aspx
|
||||
|
||||
The rest of this section deals with setting up a machine to run applications without the docker image.
|
||||
|
||||
### Get Mono
|
||||
|
||||
Mono is how .NET applications can run on platforms other than Windows, it is an ongoing effort to port the .NET framework to other platforms. In the process of developing ASP.NET 5 we worked with the Mono team to fix some bugs and add some features that we needed to run ASP.NET applications. Because these changes haven't yet made it into an official Mono release we will either grab a Mono nightly build or compile Mono from source.
|
||||
|
||||
#### Option 1: CI build
|
||||
|
||||
The Mono CI server builds packages for Linux distributions on each commit. To get them you install a particular snapshot and then run `mono-snapshot APP/VER` to change the current shell to use the provided snapshot. In these instructions we will grab the latest snapshot and set it to be the one to use.
|
||||
|
||||
**NOTE: Mono snapshots do not persist outside the current shell, you need to run `mono-snapshot` each time you want to run the newer version of Mono. If this isn't what you want then look at compiling Mono from source option, the instructions here show building from source and installing Mono. If you want other options then you should follow the links to the Mono build instructions. **
|
||||
|
||||
To do this we need to add the Mono CI server to apt-get:
|
||||
|
||||
```bash
|
||||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
|
||||
echo "deb http://jenkins.mono-project.com/repo/debian sid main" | sudo tee /etc/apt/sources.list.d/mono-jenkins.list
|
||||
sudo apt-get update
|
||||
sudo apt-get install mono-snapshot-latest
|
||||
. mono-snapshot mono
|
||||
```
|
||||
**NOTE:** Official Mono instructions that these steps come from are here: http://www.mono-project.com/docs/getting-started/install/linux/ci-packages/.
|
||||
|
||||
#### Option 2: Build from source
|
||||
|
||||
Building Mono from source can take some time, and the commands below will install the built version of Mono on your machine replacing any version you might already have.
|
||||
|
||||
```bash
|
||||
sudo apt-get install git autoconf libtool automake build-essential mono-devel gettext
|
||||
PREFIX='/usr/local'
|
||||
PATH=$PREFIX/bin:$PATH
|
||||
git clone https://github.com/mono/mono.git
|
||||
cd mono
|
||||
./autogen.sh --prefix=$PREFIX
|
||||
make
|
||||
sudo make install
|
||||
cd .. && rm -rf Mono
|
||||
mozroots --import --sync
|
||||
```
|
||||
|
||||
See http://www.mono-project.com/docs/compiling-mono/linux/ for more details and some other build options.
|
||||
|
||||
**NOTE:** Mono on Linux before 3.12 by default didn’t trust any SSL certificates so you got errors when accessing HTTPS resources. This is not required anymore as 3.12 and later include a new tool that runs on package installation and syncs Mono’s certificate store with the system certificate store (on older versions you have to import Mozilla’s list of trusted certificates by running `mozroots --import --sync`. If you get exceptions during package restore this is the most likely reason.
|
||||
|
||||
### Get libuv
|
||||
|
||||
[Libuv](https://github.com/libuv/libuv) is a multi-platform asynchronous IO library that is used by the [KestrelHttpServer](https://github.com/aspnet/KestrelHttpServer) that we will use to host our web applications.
|
||||
|
||||
To build libuv you should do the following:
|
||||
|
||||
```
|
||||
sudo apt-get install automake libtool
|
||||
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
|
||||
cd /usr/local/src/libuv-1.4.2
|
||||
sudo sh autogen.sh
|
||||
sudo ./configure
|
||||
sudo make
|
||||
sudo make install
|
||||
sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/
|
||||
sudo ldconfig
|
||||
```
|
||||
|
||||
**NOTE:** `make install` puts `libuv.so.1` in `/usr/local/lib`, in the above commands `ldconfig` is used to update `ld.so.cache` so that `dlopen` (see man dlopen) can load it. If you are getting libuv some other way or not running `make install` then you need to ensure that dlopen is capable of loading `libuv.so.1`
|
||||
|
||||
### Get DNVM
|
||||
|
||||
Now lets get DNVM. To do this run:
|
||||
|
||||
```
|
||||
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
|
||||
```
|
||||
|
||||
(TODO: Need to change dnvinstall.sh to actually put it in bin. It doesn't at the moment but should.
|
||||
dnvminstall.sh grabs and copies dnvm.sh into your Home directory (~/.dnx/bin) and sources it. It will also try and find bash or zsh profiles and add a call to source dnvm to them so that dnvm will be available all the time. If you don't like this behaviour or want to do something else then you can edit your profile after running dnvminstall.sh or do all the tasks dnvminstall does changing what you like.
|
||||
|
||||
Once this step is complete you should be able to run `dnvm` and see some help text.
|
||||
|
||||
# Add Sources to NuGet.config
|
||||
|
||||
Now that we have DNVM and the other tools needed to run an ASP.NET application we need to add the development configuration sources to get nightly builds of all the ASP.NET packages.
|
||||
|
||||
The nightly package source is: https://www.myget.org/F/aspnetvnext/api/v2/
|
||||
|
||||
To add this to your package sources you need to edit the NuGet.config.
|
||||
|
||||
Edit: ~/.config/NuGet/NuGet.config
|
||||
|
||||
The NuGet.config file should look something like the following:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2/" />
|
||||
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
|
||||
</packageSources>
|
||||
<disabledPackageSources />
|
||||
</configuration>
|
||||
```
|
||||
The important part of this is that you have a package source with aspnetvnext and nuget.org in it.
|
||||
148
README.md
148
README.md
|
|
@ -1,138 +1,99 @@
|
|||
# ASP.NET vNext Home
|
||||
Latest dev version: [](https://www.myget.org/gallery/aspnetvnext)<br>
|
||||
Latest master version: [](https://www.myget.org/gallery/aspnetmaster)
|
||||
# Getting Started with ASP.NET 5 and DNX
|
||||
|
||||
The Home repository is the starting point for people to learn about ASP.NET vNext. This repo contains samples and [documentation](https://github.com/aspnet/Home/wiki) to help folks get started and learn more about what's coming in ASP.NET vNext.
|
||||
This guide is designed to get you started building applications with the latest development versions ASP.NET 5 and DNX. This means nightly builds and potentially broken or unstable packages.
|
||||
|
||||
ASP.NET vNext is being actively developed by the ASP.NET team assigned to the Microsoft Open Tech Hub and in collaboration with a community of open source developers. Together we are dedicated to creating the best possible platform for web development.
|
||||
If you want a more stable, released, experience then you should go to http://www.asp.net/vnext.
|
||||
|
||||
The samples provided in this repo are designed to show some of the features of the new framework and to provide a starting point for further exploration. All the component packages are available on NuGet. To try out the latest bits under development switch to the dev branch of the Home repo and use the dev feed in NuGet.config (https://www.myget.org/F/aspnetvnext).
|
||||
## What you need
|
||||
|
||||
## Contents
|
||||
The key part of working with development feeds is getting your environment setup so that you can acquire and switch to new builds of the DNX. Once you have that then it is just a matter of pulling the latest packages from the development MyGet feed.
|
||||
|
||||
* [Minimum Requirements](#minimum-requirements)
|
||||
* [Getting Started](#getting-started)
|
||||
* [Samples](#samples)
|
||||
* [Documentation and Further Learning](#documentation-and-further-learning)
|
||||
* [Repos and Projects](#repos-and-projects)
|
||||
* [Feedback](#feedback)
|
||||
In order to be able to get new builds of the DNX, and switch between them, you need to get the DNX Version Manager (DNVM) command line tool.
|
||||
|
||||
## Minimum Requirements
|
||||
## Getting Started on Windows
|
||||
|
||||
These are the current minimum requirements for the latest preview release. They do not necessarily represent what the final minimum requirements will be.
|
||||
The easiest way to get started on Windows is to grab the latest CTP of Visual Studio, which can be found [here](http://go.microsoft.com/fwlink/?LinkId=521794).
|
||||
|
||||
### Windows
|
||||
* Windows 7 or Windows Server 2008 R2.
|
||||
* .NET 4.5.1 for hosting in IIS
|
||||
Visual Studio will install DNVM for you, so if you open a command prompt and type DNVM you should get some help text.
|
||||
|
||||
### OS X/Linux
|
||||
* Mono 3.4.1 or later (Note: On OS X use the Homebrew formula specified below to install the required version of Mono)
|
||||
* bash or zsh and curl
|
||||
### Upgrading DNVM or running without Visual Studio
|
||||
|
||||
## Getting Started
|
||||
|
||||
The easiest way to get started with ASP.NET vNext is to try out the latest preview of Visual Studio 2015 Preview. You can find installation instructions and getting started documentation at http://www.asp.net/vnext.
|
||||
|
||||
That said, you can also try out ASP.NET vNext with just a command-prompt and a text editor. The following instructions will walk you through getting your dev environment setup.
|
||||
|
||||
### Install the K Version Manager (KVM)
|
||||
|
||||
The first thing we need to do is setup the tools required to build and run an application. We will start out by getting the [K Version Manager (KVM)](https://github.com/aspnet/Home/wiki/version-manager). We use the K Version Manager to install different versions of the ASP.NET vNext runtime and switch between them.
|
||||
|
||||
#### Windows
|
||||
To install KVM on Windows run the following command, which will download and run a script that installs KVM for the current user (requires admin privileges for Powershell). This will use the currently released version of `kvm` (from the `release` branch of this repo).
|
||||
If you don't want to install Visual Studio or want to upgrade DNVM to the latest version then you need to run the following command:
|
||||
|
||||
####CMD
|
||||
```
|
||||
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/release/kvminstall.ps1'))"
|
||||
|
||||
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"
|
||||
```
|
||||
|
||||
If you want to run on the bleeding edge and install the latest development version of KVM, run the following command:
|
||||
|
||||
####Powershell
|
||||
```
|
||||
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/release/kvminstall.ps1'))}"
|
||||
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
|
||||
```
|
||||
|
||||
After the script has run open a new command prompt to start using KVM.
|
||||
|
||||
#### OS X:
|
||||
|
||||
To install KVM and the correct version of Mono on OS X using [Homebrew](http://brew.sh) follow the following steps:
|
||||
|
||||
* Install [Homebrew](http://brew.sh) if it is not already installed.
|
||||
* Run command `brew tap aspnet/k` to tap the ASP.NET vNext related git repositories. If you had already tapped the repo for previous releases, run `brew untap aspnet/k` to delete the old commands and tap again to get the updated brew scripts.
|
||||
* Run command `brew install kvm` to install KVM. This also automatically install the latest KRE package from https://www.nuget.org/api/v2 feed.
|
||||
* Run command `source kvm.sh` on your terminal if your terminal cannot understand kvm.
|
||||
|
||||
#### Linux:
|
||||
|
||||
Installing KVM requires `curl`. Do verify if that is installed on the machine. Next install KVM on Linux run the following command:
|
||||
This will download the DNVM script and put it in your user profile. You can check the location of DNVM by running the following in a cmd prompt:
|
||||
|
||||
```
|
||||
curl -sSL https://raw.githubusercontent.com/aspnet/Home/release/kvminstall.sh | sh && source ~/.k/kvm/kvm.sh
|
||||
where dnvm
|
||||
```
|
||||
|
||||
If you want to run on the bleeding edge and install the latest development version of KVM, use this command:
|
||||
> If the output of `where dnvm` shows a program files location before the user profile, or doesn't show an entry in user profile, then the install has either failed or your PATH is incorrect. After installing dnvm you should have the dnvm script in `%USERPROFILE%\.dnx\bin` and that path needs to be on your PATH.
|
||||
|
||||
## OS X
|
||||
|
||||
On OS X the best way to get DNVM is to use [Homebrew](http://www.brew.sh). If you don't have Homebrew installed then follow the instructions [here](http://www.brew.sh). Once you have Homebrew then run the following commands:
|
||||
|
||||
```
|
||||
curl -sSL https://raw.githubusercontent.com/aspnet/Home/release/kvminstall.sh | KVM_BRANCH=dev sh && source ~/.k/kvm/kvm.sh
|
||||
brew tap aspnet/k
|
||||
brew install dnvm
|
||||
```
|
||||
Note that on Windows the .NET framework is installed already, whereas on OS X the brew formula compiles a particular version of [Mono](http://www.mono-project.com/) that we know works with ASP.NET 5.
|
||||
|
||||
## Linux
|
||||
|
||||
* [Debian, Ubuntu and derivatives see here](GettingStartedDeb.md)
|
||||
* **CentOS, Fedora and derivatives don't currently have a seperate guide. We should have one soon. The commands are mostly the same, with some differences to account for the different package manager**
|
||||
|
||||
# Running an application
|
||||
|
||||
Now we should have an environment that works and you can should be able to run an ASP.NET 5 application
|
||||
|
||||
The first thin to do is download a DNX to run your applications with:
|
||||
|
||||
```
|
||||
dnvm upgrade
|
||||
```
|
||||
|
||||
Note that on Linux you need to also install [Mono](http://mono-project.com) 3.4.1 or later.
|
||||
> DNVM has the concept of a stable and unstable feed. Stable defaults to NuGet.org while unstable defaults to our dev MyGet feed. So if you add `-u` or `-unstable` to any of the install or upgrade commands you will get our latest CI build of the DNX instead of the one last released on NuGet.
|
||||
|
||||
### Install the K Runtime Environment (KRE)
|
||||
DNVM works by manipulating your path. When you install a runtime it downloads it and adds the path to the dnx binary to your `PATH`. After doing upgrade you should be able to run `dnvm list` and see an active runtime in the list.
|
||||
|
||||
Now that you have KVM setup you can install the latest version of the runtime by running the following command: ```kvm upgrade```
|
||||
|
||||
This command will download the specified version of the K Runtime Environment (KRE), and put it on your user profile ready to use. You are now ready to start using ASP.NET vNext!
|
||||
You should also be able to run `dnx` and see the help text of the `dnx` command.
|
||||
|
||||
## Samples
|
||||
## Running the samples
|
||||
|
||||
The samples in this repo are basic starting points for you to experiment with.
|
||||
|
||||
+ [ConsoleApp](https://github.com/aspnet/Home/tree/release/samples/ConsoleApp). This is just basic console app if you want to use it as a starting point.
|
||||
+ [HelloWeb](https://github.com/aspnet/Home/tree/release/samples/HelloWeb). This is a minimal startup class that shows welcome page and static file middleware. This is mostly for you to run through the steps in the readme and make sure you have everything setup and working correctly.
|
||||
+ [HelloMvc](https://github.com/aspnet/Home/tree/release/samples/HelloMvc). This sample is a basic MVC app. It is not designed to show all the functionality of the new web stack, but to give you a starting point to play with features.
|
||||
+ [MVC Music Store](https://github.com/aspnet/MusicStore) and [BugTracker](https://github.com/aspnet/BugTracker) are application samples that are both being ported to ASP.NET vNext. Each of these samples have their own separate repositories that you can look at.
|
||||
|
||||
### Running the samples
|
||||
|
||||
1. Clone the Home repository
|
||||
1. Clone the ASP.NET 5 Home repository: https://github.com/aspnet/home
|
||||
2. Change directory to the folder of the sample you want to run
|
||||
3. Run ```dnu restore``` to restore the packages required by that sample.
|
||||
4. You should see a bunch of output as all the dependencies of the app are downloaded from MyGet.
|
||||
5. Run the sample using the appropriate K command:
|
||||
- For the console app run ```k run```.
|
||||
- For the web apps run ```k web``` on Windows or ```k kestrel``` on Mono.
|
||||
- For the console app run `dnx . run`.
|
||||
- For the web apps run `dnx . web` on Windows or `dnx . kestrel` on OS X/Linux.
|
||||
6. You should see the output of the console app or a message that says the site is now started.
|
||||
7. You can navigate to the web apps in a browser by going to "http://localhost:5001" or "http://localhost:5004" if running on Mono.
|
||||
7. You can navigate to the web apps in a browser by going to "http://localhost:5001" or "http://localhost:5004" if running on OS X/Linux.
|
||||
|
||||
### Switching to Core CLR
|
||||
# Documentation and Further Learning
|
||||
|
||||
By default when running ASP.NET vNext applications on the Windows platform you are running on the full .NET Framework. You can switch to use the new Cloud Optimized runtime, or Core CLR, using the KVM command.
|
||||
|
||||
1. Run ```kvm upgrade -runtime CoreCLR``` This command gets the latest Core CLR version of the k runtime and sets it as your default. The `-runtime CoreCLR` switch tells it to use Core CLR. You can use `-r CLR` to target desktop again.
|
||||
2. Run ```k web``` to run on WebListener.
|
||||
3. The first line of your output should say "Loaded Module: klr.core45.dll" instead of "Loaded Module: klr.net45.dll"
|
||||
4. The HelloWeb app should work the same as when running on the full desktop .NET Framework but now as a fully self-contained app with true side-by-side versioning support.
|
||||
|
||||
**NOTE: There are many APIs from the .NET Framework that are not yet available when running on Core CLR. This set should get smaller and smaller as time goes on.**
|
||||
|
||||
**NOTE: There is no Core CLR currently available on OSX/Linux. There is only a single platform (mono45) and a single architecture (x86).**
|
||||
|
||||
## Documentation and Further Learning
|
||||
|
||||
### [Community Standup](http://www.youtube.com/playlist?list=PL0M0zPgJ3HSftTAAHttA3JQU4vOjXFquF)
|
||||
## [Community Standup](http://www.youtube.com/playlist?list=PL0M0zPgJ3HSftTAAHttA3JQU4vOjXFquF)
|
||||
The community standup is held every week and streamed live to YouTube. You can view past standups in the linked playlist.
|
||||
|
||||
If you have questions you can also jump online during the next standup and have them answered live.
|
||||
|
||||
### [Wiki Documentation](https://github.com/aspnet/Home/wiki)
|
||||
## [Wiki Documentation](https://github.com/aspnet/Home/wiki)
|
||||
We have some useful documentation on the wiki of this Repo. This wiki is a central spot for docs from any part of the stack.
|
||||
|
||||
If you see errors, or want some extra content, then feel free to create an issue or send a pull request (see feedback section below).
|
||||
|
||||
### [ASP.NET/vNext](http://www.asp.net/vnext)
|
||||
## [ASP.NET/vNext](http://www.asp.net/vnext)
|
||||
The vNext page on the ASP.NET site has links to some TechEd videos and articles with some good information about vNext.
|
||||
|
||||
## Repos and Projects
|
||||
|
|
@ -142,12 +103,13 @@ These are some of the most common repos:
|
|||
* [DependencyInjection](https://github.com/aspnet/DependencyInjection) - basic dependency injection infrastructure and default implementation
|
||||
* [EntityFramework](https://github.com/aspnet/EntityFramework) - data access technology
|
||||
* [Identity](https://github.com/aspnet/Identity) - users and membership system
|
||||
* [DNX](https://github.com/aspnet/dnx) - core runtime, project system, loader
|
||||
* [DNX](https://github.com/aspnet/DNX) - core runtime, project system, loader
|
||||
* [MVC](https://github.com/aspnet/Mvc) - MVC framework for web apps and services
|
||||
* [SignalR-Server](https://github.com/aspnet/SignalR-Server) - real-time
|
||||
|
||||
A description of all the repos is [here](https://github.com/aspnet/Home/wiki/Repo-List).
|
||||
|
||||
## Feedback
|
||||
# Feedback
|
||||
|
||||
Check out the [contributing](https://github.com/aspnet/Home/blob/release/CONTRIBUTING.md) page to see the best places to log issues and start discussions.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
@Echo off
|
||||
|
||||
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0dotnetsdk.ps1' %*"
|
||||
|
||||
IF EXIST "%USERPROFILE%\.dotnet\temp-set-envvars.cmd" (
|
||||
CALL "%USERPROFILE%\.dotnet\temp-set-envvars.cmd"
|
||||
DEL "%USERPROFILE%\.dotnet\temp-set-envvars.cmd"
|
||||
)
|
||||
774
dotnetsdk.ps1
774
dotnetsdk.ps1
|
|
@ -1,774 +0,0 @@
|
|||
param(
|
||||
[parameter(Position=0)]
|
||||
[string] $Command,
|
||||
[string] $Proxy,
|
||||
[switch] $Verbosity = $false,
|
||||
[alias("p")][switch] $Persistent = $false,
|
||||
[alias("f")][switch] $Force = $false,
|
||||
[alias("r")][string] $Runtime,
|
||||
|
||||
[alias("arch")][string] $Architecture,
|
||||
[switch] $X86 = $false,
|
||||
[alias("amd64")][switch] $X64 = $false,
|
||||
|
||||
[alias("w")][switch] $Wait = $false,
|
||||
[alias("a")]
|
||||
[string] $Alias = $null,
|
||||
[switch] $NoNative = $false,
|
||||
[parameter(Position=1, ValueFromRemainingArguments=$true)]
|
||||
[string[]]$Args=@(),
|
||||
[switch] $Quiet,
|
||||
[string] $OutputVariable,
|
||||
[switch] $AssumeElevated
|
||||
)
|
||||
|
||||
# "Constants" (in as much as PowerShell will allow)
|
||||
$RuntimePackageName = "dotnet"
|
||||
$RuntimeFriendlyName = ".NET Runtime"
|
||||
$RuntimeProgramFilesName = "Microsoft .NET Cross-Platform Runtime"
|
||||
$RuntimeFolderName = ".dotnet"
|
||||
$DefaultFeed = "https://www.myget.org/F/aspnetvnext/api/v2"
|
||||
$CrossGenCommand = "k-crossgen"
|
||||
|
||||
$selectedArch=$null;
|
||||
$defaultArch="x86"
|
||||
$selectedRuntime=$null
|
||||
$defaultRuntime="clr"
|
||||
|
||||
# Get or calculate userDotNetPath
|
||||
$userDotNetPath = $env:DOTNET_USER_PATH
|
||||
if(!$userDotNetPath) { $userDotNetPath = $env:USERPROFILE + "\$RuntimeFolderName" }
|
||||
$userDotNetRuntimesPath = $userDotNetPath + "\runtimes"
|
||||
|
||||
# Get the feed from the environment variable or set it to the default value
|
||||
$feed = $env:DOTNET_FEED
|
||||
if (!$feed)
|
||||
{
|
||||
$feed = $DefaultFeed;
|
||||
}
|
||||
$feed = $feed.TrimEnd("/")
|
||||
|
||||
# In some environments, like Azure Websites, the Write-* cmdlets don't work
|
||||
$useHostOutputMethods = $true
|
||||
|
||||
function String-IsEmptyOrWhitespace([string]$str) {
|
||||
return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0
|
||||
}
|
||||
|
||||
$scriptPath = $myInvocation.MyCommand.Definition
|
||||
|
||||
function DotNetSdk-Help {
|
||||
@"
|
||||
.NET SDK Manager - Build 10305
|
||||
|
||||
USAGE: dotnetsdk <command> [options]
|
||||
|
||||
dotnetsdk upgrade [-X86|-X64] [-r|-Runtime CLR|CoreCLR] [-g|-Global] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
|
||||
install latest .NET Runtime from feed
|
||||
set 'default' alias to installed version
|
||||
add KRE bin to user PATH environment variable
|
||||
-g|-Global install to machine-wide location
|
||||
-f|-Force upgrade even if latest is already installed
|
||||
-Proxy <ADDRESS> use given address as proxy when accessing remote server (e.g. https://username:password@proxyserver:8080/). Alternatively set proxy using http_proxy environment variable.
|
||||
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
|
||||
|
||||
dotnetsdk install <semver>|<alias>|<nupkg>|latest [-X86|-X64] [-r|-Runtime CLR|CoreCLR] [-a|-Alias <alias>] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
|
||||
<semver>|<alias> install requested .NET Runtime from feed
|
||||
<nupkg> install requested .NET Runtime from package on local filesystem
|
||||
latest install latest .NET Runtime from feed
|
||||
add .NET Runtime bin to path of current command line
|
||||
-p|-Persistent add .NET Runtime bin to PATH environment variables persistently
|
||||
-a|-Alias <alias> set alias <alias> for requested .NET Runtime on install
|
||||
-f|-Force install even if specified version is already installed
|
||||
-Proxy <ADDRESS> use given address as proxy when accessing remote server (e.g. https://username:password@proxyserver:8080/). Alternatively set proxy using http_proxy environment variable.
|
||||
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
|
||||
|
||||
dotnetsdk use <semver>|<alias>|<package>|none [-X86|-X64] [-r|-Runtime CLR|CoreCLR] [-p|-Persistent]
|
||||
<semver>|<alias>|<package> add .NET Runtime bin to path of current command line
|
||||
none remove .NET Runtime bin from path of current command line
|
||||
-p|-Persistent add .NET Runtime bin to PATH environment variable across all processes run by the current user
|
||||
|
||||
dotnetsdk list
|
||||
list .NET Runtime versions installed
|
||||
|
||||
dotnetsdk alias
|
||||
list .NET Runtime aliases which have been defined
|
||||
|
||||
dotnetsdk alias <alias>
|
||||
display value of the specified alias
|
||||
|
||||
dotnetsdk alias <alias> <semver>|<alias>|<package> [-X86|-X64] [-r|-Runtime CLR|CoreCLR]
|
||||
<alias> the name of the alias to set
|
||||
<semver>|<alias>|<package> the .NET Runtime version to set the alias to. Alternatively use the version of the specified alias
|
||||
|
||||
dotnetsdk unalias <alias>
|
||||
remove the specified alias
|
||||
|
||||
"@ -replace "`n","`r`n" | Console-Write
|
||||
}
|
||||
|
||||
function DotNetSdk-Global-Setup {
|
||||
# Sets up the 'dotnetsdk' tool and adds the user-local dotnet install directory to the DOTNET_HOME variable
|
||||
# Note: We no longer do global install via this tool. The MSI handles global install of runtimes AND will set
|
||||
# the machine level DOTNET_HOME value.
|
||||
|
||||
# In this configuration, the user-level path will OVERRIDE the global path because it is placed first.
|
||||
|
||||
$dotnetsdkBinPath = "$userDotNetPath\bin"
|
||||
|
||||
If (Needs-Elevation)
|
||||
{
|
||||
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -wait"
|
||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||
Console-Write "Adding $dotnetsdkBinPath to process PATH"
|
||||
Set-Path (Change-Path $env:Path $dotnetsdkBinPath ($dotnetsdkBinPath))
|
||||
Console-Write "Adding %USERPROFILE%\$RuntimeFolderName to process DOTNET_HOME"
|
||||
$envDotNetHome = $env:DOTNET_HOME
|
||||
$envDotNetHome = Change-Path $envDotNetHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
|
||||
$env:DOTNET_HOME = $envDotNetHome
|
||||
Console-Write "Setup complete"
|
||||
break
|
||||
}
|
||||
|
||||
$scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath)
|
||||
|
||||
Console-Write "Copying file $dotnetsdkBinPath\dotnetsdk.ps1"
|
||||
md $dotnetsdkBinPath -Force | Out-Null
|
||||
copy "$scriptFolder\dotnetsdk.ps1" "$dotnetsdkBinPath\dotnetsdk.ps1"
|
||||
|
||||
Console-Write "Copying file $dotnetsdkBinPath\dotnetsdk.cmd"
|
||||
copy "$scriptFolder\dotnetsdk.cmd" "$dotnetsdkBinPath\dotnetsdk.cmd"
|
||||
|
||||
Console-Write "Adding $dotnetsdkBinPath to process PATH"
|
||||
Set-Path (Change-Path $env:Path $dotnetsdkBinPath ($dotnetsdkBinPath))
|
||||
|
||||
Console-Write "Adding $dotnetsdkBinPath to user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath $dotnetsdkBinPath ($dotnetsdkBinPath)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
|
||||
Console-Write "Adding %USERPROFILE%\$RuntimeFolderName to process DOTNET_HOME"
|
||||
$envDotNetHome = $env:DOTNET_HOME
|
||||
$envDotNetHome = Change-Path $envDotNetHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
|
||||
$env:DOTNET_HOME = $envDotNetHome
|
||||
|
||||
Console-Write "Adding %USERPROFILE%\$RuntimeFolderName to machine DOTNET_HOME"
|
||||
$machineDotNetHome = [Environment]::GetEnvironmentVariable("DOTNET_HOME", [System.EnvironmentVariableTarget]::Machine)
|
||||
$machineDotNetHome = Change-Path $machineDotNetHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
|
||||
[Environment]::SetEnvironmentVariable("DOTNET_HOME", $machineDotNetHome, [System.EnvironmentVariableTarget]::Machine)
|
||||
}
|
||||
|
||||
function DotNetSdk-Upgrade {
|
||||
param(
|
||||
[boolean] $isGlobal
|
||||
)
|
||||
$Persistent = $true
|
||||
$Alias="default"
|
||||
DotNetSdk-Install "latest" $isGlobal
|
||||
}
|
||||
|
||||
function Add-Proxy-If-Specified {
|
||||
param(
|
||||
[System.Net.WebClient] $wc
|
||||
)
|
||||
if (!$Proxy) {
|
||||
$Proxy = $env:http_proxy
|
||||
}
|
||||
if ($Proxy) {
|
||||
$wp = New-Object System.Net.WebProxy($Proxy)
|
||||
$pb = New-Object UriBuilder($Proxy)
|
||||
if (!$pb.UserName) {
|
||||
$wp.Credentials = [System.Net.CredentialCache]::DefaultCredentials
|
||||
} else {
|
||||
$wp.Credentials = New-Object System.Net.NetworkCredential($pb.UserName, $pb.Password)
|
||||
}
|
||||
$wc.Proxy = $wp
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Find-Latest {
|
||||
param(
|
||||
[string] $platform,
|
||||
[string] $architecture
|
||||
)
|
||||
Console-Write "Determining latest version"
|
||||
|
||||
$url = "$feed/GetUpdates()?packageIds=%27$RuntimePackageName-$platform-win-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
Add-Proxy-If-Specified($wc)
|
||||
Write-Verbose "Downloading $url ..."
|
||||
[xml]$xml = $wc.DownloadString($url)
|
||||
|
||||
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
|
||||
|
||||
if (String-IsEmptyOrWhitespace($version)) {
|
||||
throw "There are no runtimes for platform '$platform', architecture '$architecture' in the feed '$feed'"
|
||||
}
|
||||
|
||||
return $version
|
||||
}
|
||||
|
||||
function Do-DotNetSdk-Download {
|
||||
param(
|
||||
[string] $runtimeFullName,
|
||||
[string] $runtimesFolder
|
||||
)
|
||||
$parts = $runtimeFullName.Split(".", 2)
|
||||
|
||||
$url = "$feed/package/" + $parts[0] + "/" + $parts[1]
|
||||
$runtimeFolder = Join-Path $runtimesFolder $runtimeFullName
|
||||
$runtimeFile = Join-Path $runtimeFolder "$runtimeFullName.nupkg"
|
||||
|
||||
If (Test-Path $runtimeFolder) {
|
||||
if($Force)
|
||||
{
|
||||
rm $runtimeFolder -Recurse -Force
|
||||
} else {
|
||||
Console-Write "$runtimeFullName already installed."
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Console-Write "Downloading $runtimeFullName from $feed"
|
||||
|
||||
#Downloading to temp location
|
||||
$runtimeTempDownload = Join-Path $runtimesFolder "temp"
|
||||
$tempDownloadFile = Join-Path $runtimeTempDownload "$runtimeFullName.nupkg"
|
||||
|
||||
if(Test-Path $runtimeTempDownload) {
|
||||
del "$runtimeTempDownload\*" -recurse
|
||||
} else {
|
||||
md $runtimeTempDownload -Force | Out-Null
|
||||
}
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
Add-Proxy-If-Specified($wc)
|
||||
Write-Verbose "Downloading $url ..."
|
||||
$wc.DownloadFile($url, $tempDownloadFile)
|
||||
|
||||
Do-DotNetSdk-Unpack $tempDownloadFile $runtimeTempDownload
|
||||
|
||||
md $runtimeFolder -Force | Out-Null
|
||||
Console-Write "Installing to $runtimeFolder"
|
||||
mv "$runtimeTempDownload\*" $runtimeFolder
|
||||
Remove-Item "$runtimeTempDownload" -Force | Out-Null
|
||||
}
|
||||
|
||||
function Do-DotNetSdk-Unpack {
|
||||
param(
|
||||
[string] $runtimeFile,
|
||||
[string] $runtimeFolder
|
||||
)
|
||||
Console-Write "Unpacking to $runtimeFolder"
|
||||
|
||||
$compressionLib = [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
|
||||
|
||||
if($compressionLib -eq $null) {
|
||||
try {
|
||||
# Shell will not recognize nupkg as a zip and throw, so rename it to zip
|
||||
$runtimeZip = [System.IO.Path]::ChangeExtension($runtimeFile, "zip")
|
||||
Rename-Item $runtimeFile $runtimeZip
|
||||
# Use the shell to uncompress the nupkg
|
||||
$shell_app=new-object -com shell.application
|
||||
$zip_file = $shell_app.namespace($runtimeZip)
|
||||
$destination = $shell_app.namespace($runtimeFolder)
|
||||
$destination.Copyhere($zip_file.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files
|
||||
}
|
||||
finally {
|
||||
# make it a nupkg again
|
||||
Rename-Item $runtimeZip $runtimeFile
|
||||
}
|
||||
} else {
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($runtimeFile, $runtimeFolder)
|
||||
}
|
||||
|
||||
If (Test-Path ($runtimeFolder + "\[Content_Types].xml")) {
|
||||
Remove-Item ($runtimeFolder + "\[Content_Types].xml")
|
||||
}
|
||||
If (Test-Path ($runtimeFolder + "\_rels\")) {
|
||||
Remove-Item ($runtimeFolder + "\_rels\") -Force -Recurse
|
||||
}
|
||||
If (Test-Path ($runtimeFolder + "\package\")) {
|
||||
Remove-Item ($runtimeFolder + "\package\") -Force -Recurse
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Install {
|
||||
param(
|
||||
[string] $versionOrAlias,
|
||||
[boolean] $isGlobal
|
||||
)
|
||||
if ($versionOrAlias -eq "latest") {
|
||||
$versionOrAlias = DotNetSdk-Find-Latest (Requested-Platform $defaultRuntime) (Requested-Architecture $defaultArch)
|
||||
}
|
||||
|
||||
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||
$runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
|
||||
} else {
|
||||
$runtimeFullName = Requested-VersionOrAlias $versionOrAlias
|
||||
}
|
||||
|
||||
$packageFolder = $userDotNetRuntimesPath
|
||||
|
||||
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||
Set-Variable -Name "selectedArch" -Value (Package-Arch $runtimeFullName) -Scope Script
|
||||
Set-Variable -Name "selectedRuntime" -Value (Package-Platform $runtimeFullName) -Scope Script
|
||||
|
||||
$runtimeFolder = "$packageFolder\$runtimeFullName"
|
||||
$folderExists = Test-Path $runtimeFolder
|
||||
|
||||
if ($folderExists -and $Force) {
|
||||
del $runtimeFolder -Recurse -Force
|
||||
$folderExists = $false;
|
||||
}
|
||||
|
||||
if ($folderExists) {
|
||||
Console-Write "Target folder '$runtimeFolder' already exists"
|
||||
} else {
|
||||
$tempUnpackFolder = Join-Path $packageFolder "temp"
|
||||
$tempDownloadFile = Join-Path $tempUnpackFolder "$runtimeFullName.nupkg"
|
||||
|
||||
if(Test-Path $tempUnpackFolder) {
|
||||
del "$tempUnpackFolder\*" -recurse
|
||||
} else {
|
||||
md $tempUnpackFolder -Force | Out-Null
|
||||
}
|
||||
copy $versionOrAlias $tempDownloadFile
|
||||
|
||||
Do-DotNetSdk-Unpack $tempDownloadFile $tempUnpackFolder
|
||||
md $runtimeFolder -Force | Out-Null
|
||||
Console-Write "Installing to $runtimeFolder"
|
||||
mv "$tempUnpackFolder\*" $runtimeFolder
|
||||
Remove-Item "$tempUnpackFolder" -Force | Out-Null
|
||||
}
|
||||
|
||||
$packageVersion = Package-Version $runtimeFullName
|
||||
|
||||
DotNetSdk-Use $packageVersion
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {
|
||||
DotNetSdk-Alias-Set $Alias $packageVersion
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Do-DotNetSdk-Download $runtimeFullName $packageFolder
|
||||
DotNetSdk-Use $versionOrAlias
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {
|
||||
DotNetSdk-Alias-Set "$Alias" $versionOrAlias
|
||||
}
|
||||
}
|
||||
|
||||
if ($runtimeFullName.Contains("CoreCLR")) {
|
||||
if ($NoNative) {
|
||||
Console-Write "Native image generation is skipped"
|
||||
}
|
||||
else {
|
||||
Console-Write "Compiling native images for $runtimeFullName to improve startup performance..."
|
||||
Start-Process $CrossGenCommand -Wait
|
||||
Console-Write "Finished native image compilation."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-List {
|
||||
$dotnetHome = $env:DOTNET_HOME
|
||||
if (!$dotnetHome) {
|
||||
$dotnetHome = "$userDotNetPath"
|
||||
}
|
||||
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
$aliases = Get-ChildItem ($userDotNetPath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }}
|
||||
|
||||
$items = @()
|
||||
foreach($portion in $dotnetHome.Split(';')) {
|
||||
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
|
||||
if (Test-Path("$path\runtimes")) {
|
||||
$items += Get-ChildItem ("$path\runtimes\dotnet-*") | List-Parts $aliases
|
||||
}
|
||||
}
|
||||
|
||||
$items | Sort-Object Version, Runtime, Architecture, Alias | Format-Table -AutoSize -Property @{name="Active";expression={$_.Active};alignment="center"}, "Version", "Runtime", "Architecture", "Location", "Alias"
|
||||
}
|
||||
|
||||
filter List-Parts {
|
||||
param($aliases)
|
||||
|
||||
$hasBin = Test-Path($_.FullName+"\bin")
|
||||
if (!$hasBin) {
|
||||
return
|
||||
}
|
||||
$active = $false
|
||||
foreach($portion in $env:Path.Split(';')) {
|
||||
# Append \ to the end because otherwise you might see
|
||||
# multiple active versions if the folders have the same
|
||||
# name prefix (like 1.0-beta and 1.0)
|
||||
if ($portion.StartsWith($_.FullName + "\")) {
|
||||
$active = $true
|
||||
}
|
||||
}
|
||||
|
||||
$fullAlias=""
|
||||
$delim=""
|
||||
|
||||
foreach($alias in $aliases){
|
||||
if($_.Name.Split('\', 2) -contains $alias.Name){
|
||||
$fullAlias += $delim + $alias.Alias
|
||||
$delim = ", "
|
||||
}
|
||||
}
|
||||
|
||||
$parts1 = $_.Name.Split('.', 2)
|
||||
$parts2 = $parts1[0].Split('-', 4)
|
||||
return New-Object PSObject -Property @{
|
||||
Active = if ($active) { "*" } else { "" }
|
||||
Version = $parts1[1]
|
||||
Runtime = $parts2[1]
|
||||
OperatingSystem = $parts2[2]
|
||||
Architecture = $parts2[3]
|
||||
Location = $_.Parent.FullName
|
||||
Alias = $fullAlias
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Use {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
|
||||
|
||||
if ($versionOrAlias -eq "none") {
|
||||
Console-Write "Removing .NET Runtime from process PATH"
|
||||
Set-Path (Change-Path $env:Path "" ($userDotNetRuntimesPath))
|
||||
|
||||
if ($Persistent) {
|
||||
Console-Write "Removing .NET Runtime from user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath "" ($userDotNetRuntimesPath)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$runtimeFullName = Requested-VersionOrAlias $versionOrAlias
|
||||
|
||||
$runtimeBin = Locate-DotNetBinFromFullName $runtimeFullName
|
||||
if ($runtimeBin -eq $null) {
|
||||
throw "Cannot find $runtimeFullName, do you need to run 'dotnetsdk install $versionOrAlias'?"
|
||||
}
|
||||
|
||||
Console-Write "Adding $runtimeBin to process PATH"
|
||||
Set-Path (Change-Path $env:Path $runtimeBin ($userDotNetRuntimesPath))
|
||||
|
||||
if ($Persistent) {
|
||||
Console-Write "Adding $runtimeBin to user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath $runtimeBin ($userDotNetRuntimesPath)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Alias-List {
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
|
||||
Get-ChildItem ($userDotNetPath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
|
||||
}
|
||||
|
||||
function DotNetSdk-Alias-Get {
|
||||
param(
|
||||
[string] $name
|
||||
)
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
$aliasFilePath=$userDotNetPath + "\alias\" + $name + ".txt"
|
||||
if (!(Test-Path $aliasFilePath)) {
|
||||
Console-Write "Alias '$name' does not exist"
|
||||
$script:exitCode = 1 # Return non-zero exit code for scripting
|
||||
} else {
|
||||
$aliasValue = (Get-Content ($userDotNetPath + "\alias\" + $name + ".txt"))
|
||||
Console-Write "Alias '$name' is set to $aliasValue"
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Alias-Set {
|
||||
param(
|
||||
[string] $name,
|
||||
[string] $value
|
||||
)
|
||||
$runtimeFullName = Requested-VersionOrAlias $value
|
||||
$aliasFilePath = $userDotNetPath + "\alias\" + $name + ".txt"
|
||||
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
|
||||
Console-Write "$action alias '$name' to '$runtimeFullName'"
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
$runtimeFullName | Out-File ($aliasFilePath) ascii
|
||||
}
|
||||
|
||||
function DotNetSdk-Unalias {
|
||||
param(
|
||||
[string] $name
|
||||
)
|
||||
$aliasPath=$userDotNetPath + "\alias\" + $name + ".txt"
|
||||
if (Test-Path -literalPath "$aliasPath") {
|
||||
Console-Write "Removing alias $name"
|
||||
Remove-Item -literalPath $aliasPath
|
||||
} else {
|
||||
Console-Write "Cannot remove alias, '$name' is not a valid alias name"
|
||||
$script:exitCode = 1 # Return non-zero exit code for scripting
|
||||
}
|
||||
}
|
||||
|
||||
function Locate-DotNetBinFromFullName() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
$dotnetHome = $env:DOTNET_HOME
|
||||
if (!$dotnetHome) {
|
||||
$dotnetHome = "$globalDotNetPath;$userDotNetPath"
|
||||
}
|
||||
foreach($portion in $dotnetHome.Split(';')) {
|
||||
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
|
||||
$runtimeBin = "$path\runtimes\$runtimeFullName\bin"
|
||||
if (Test-Path "$runtimeBin") {
|
||||
return $runtimeBin
|
||||
}
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Package-Version() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
return $runtimeFullName -replace '[^.]*.(.*)', '$1'
|
||||
}
|
||||
|
||||
function Package-Platform() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
return $runtimeFullName -replace 'dotnet-([^-]*).*', '$1'
|
||||
}
|
||||
|
||||
function Package-Arch() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
return $runtimeFullName -replace 'dotnet-[^-]*-[^-]*-([^.]*).*', '$1'
|
||||
}
|
||||
|
||||
|
||||
function Requested-VersionOrAlias() {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
|
||||
|
||||
$runtimeBin = Locate-DotNetBinFromFullName $versionOrAlias
|
||||
|
||||
# If the name specified is an existing package, just use it as is
|
||||
if ($runtimeBin -ne $null) {
|
||||
return $versionOrAlias
|
||||
}
|
||||
|
||||
If (Test-Path ($userDotNetPath + "\alias\" + $versionOrAlias + ".txt")) {
|
||||
$aliasValue = Get-Content ($userDotNetPath + "\alias\" + $versionOrAlias + ".txt")
|
||||
# Split dotnet-coreclr-win-x86.1.0.0-beta3-10922 into version and name sections
|
||||
$parts = $aliasValue.Split('.', 2)
|
||||
$pkgVersion = $parts[1]
|
||||
# dotnet-coreclr-win-x86
|
||||
$parts = $parts[0].Split('-', 4)
|
||||
$pkgPlatform = Requested-Platform $parts[1]
|
||||
$pkgArchitecture = Requested-Architecture $parts[3]
|
||||
} else {
|
||||
$pkgVersion = $versionOrAlias
|
||||
$pkgPlatform = Requested-Platform $defaultRuntime
|
||||
$pkgArchitecture = Requested-Architecture $defaultArch
|
||||
}
|
||||
return $RuntimePackageName + "-" + $pkgPlatform + "-win-" + $pkgArchitecture + "." + $pkgVersion
|
||||
}
|
||||
|
||||
function Requested-Platform() {
|
||||
param(
|
||||
[string] $default
|
||||
)
|
||||
if (!(String-IsEmptyOrWhitespace($selectedRuntime))) {return $selectedRuntime}
|
||||
return $default
|
||||
}
|
||||
|
||||
function Requested-Architecture() {
|
||||
param(
|
||||
[string] $default
|
||||
)
|
||||
if (!(String-IsEmptyOrWhitespace($selectedArch))) {return $selectedArch}
|
||||
return $default
|
||||
}
|
||||
|
||||
function Change-Path() {
|
||||
param(
|
||||
[string] $existingPaths,
|
||||
[string] $prependPath,
|
||||
[string[]] $removePaths
|
||||
)
|
||||
$newPath = $prependPath
|
||||
foreach($portion in $existingPaths.Split(';')) {
|
||||
$skip = $portion -eq ""
|
||||
foreach($removePath in $removePaths) {
|
||||
if ($removePath -and ($portion.StartsWith($removePath))) {
|
||||
$skip = $true
|
||||
}
|
||||
}
|
||||
if (!$skip) {
|
||||
$newPath = $newPath + ";" + $portion
|
||||
}
|
||||
}
|
||||
return $newPath
|
||||
}
|
||||
|
||||
function Set-Path() {
|
||||
param(
|
||||
[string] $newPath
|
||||
)
|
||||
md $userDotNetPath -Force | Out-Null
|
||||
$env:Path = $newPath
|
||||
@"
|
||||
SET "PATH=$newPath"
|
||||
"@ | Out-File ($userDotNetPath + "\temp-set-envvars.cmd") ascii
|
||||
}
|
||||
|
||||
function Needs-Elevation() {
|
||||
if($AssumeElevated) {
|
||||
return $false
|
||||
}
|
||||
|
||||
$user = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$elevated = $user.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
||||
return -NOT $elevated
|
||||
}
|
||||
|
||||
function Requested-Switches() {
|
||||
$arguments = ""
|
||||
if ($X86) {$arguments = "$arguments -x86"}
|
||||
if ($X64) {$arguments = "$arguments -x64"}
|
||||
if ($selectedRuntime) {$arguments = "$arguments -runtime $selectedRuntime"}
|
||||
if ($Persistent) {$arguments = "$arguments -persistent"}
|
||||
if ($Force) {$arguments = "$arguments -force"}
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {$arguments = "$arguments -alias '$Alias'"}
|
||||
return $arguments
|
||||
}
|
||||
|
||||
function Validate-And-Santitize-Switches()
|
||||
{
|
||||
if ($X86 -and $X64) {throw "You cannot select both x86 and x64 architectures"}
|
||||
|
||||
if ($Runtime) {
|
||||
$validRuntimes = "CoreCLR", "CLR"
|
||||
$match = $validRuntimes | ? { $_ -like $Runtime } | Select -First 1
|
||||
if (!$match) {throw "'$runtime' is not a valid runtime"}
|
||||
Set-Variable -Name "selectedRuntime" -Value $match.ToLowerInvariant() -Scope Script
|
||||
}
|
||||
|
||||
if($Architecture) {
|
||||
$validArchitectures = "x64", "x86"
|
||||
$match = $validArchitectures | ? { $_ -like $Architecture } | Select -First 1
|
||||
if(!$match) {throw "'$architecture' is not a valid architecture"}
|
||||
Set-Variable -Name "selectedArch" -Value $match.ToLowerInvariant() -Scope Script
|
||||
}
|
||||
else {
|
||||
if ($X64) {
|
||||
Set-Variable -Name "selectedArch" -Value "x64" -Scope Script
|
||||
} elseif ($X86) {
|
||||
Set-Variable -Name "selectedArch" -Value "x86" -Scope Script
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$script:capturedOut = @()
|
||||
function Console-Write() {
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$true)]
|
||||
[string] $message
|
||||
)
|
||||
if($OutputVariable) {
|
||||
# Update the capture output
|
||||
$script:capturedOut += @($message)
|
||||
}
|
||||
|
||||
if(!$Quiet) {
|
||||
if ($useHostOutputMethods) {
|
||||
try {
|
||||
Write-Host $message
|
||||
}
|
||||
catch {
|
||||
$script:useHostOutputMethods = $false
|
||||
Console-Write $message
|
||||
}
|
||||
}
|
||||
else {
|
||||
[Console]::WriteLine($message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Console-Write-Error() {
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$true)]
|
||||
[string] $message
|
||||
)
|
||||
if ($useHostOutputMethods) {
|
||||
try {
|
||||
Write-Error $message
|
||||
}
|
||||
catch {
|
||||
$script:useHostOutputMethods = $false
|
||||
Console-Write-Error $message
|
||||
}
|
||||
}
|
||||
else {
|
||||
[Console]::Error.WriteLine($message)
|
||||
}
|
||||
}
|
||||
|
||||
function Validate-Full-Package-Name-Arguments-Combination() {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
if ($versionOrAlias -like "dotnet-*" -and
|
||||
($selectedArch -or $selectedRuntime)) {
|
||||
throw "Runtime or architecture cannot be specified when using the full package name."
|
||||
}
|
||||
}
|
||||
|
||||
$script:exitCode = 0
|
||||
try {
|
||||
Validate-And-Santitize-Switches
|
||||
switch -wildcard ($Command + " " + $Args.Count) {
|
||||
"setup 0" {DotNetSdk-Global-Setup}
|
||||
"upgrade 0" {DotNetSdk-Upgrade $false}
|
||||
"install 1" {DotNetSdk-Install $Args[0] $false}
|
||||
"list 0" {DotNetSdk-List}
|
||||
"use 1" {DotNetSdk-Use $Args[0]}
|
||||
"alias 0" {DotNetSdk-Alias-List}
|
||||
"alias 1" {DotNetSdk-Alias-Get $Args[0]}
|
||||
"alias 2" {DotNetSdk-Alias-Set $Args[0] $Args[1]}
|
||||
"unalias 1" {DotNetSdk-Unalias $Args[0]}
|
||||
"help 0" {DotNetSdk-Help}
|
||||
" 0" {DotNetSdk-Help}
|
||||
default {throw "Unknown command"};
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Console-Write-Error $_
|
||||
Console-Write "Type 'dotnetsdk help' for help on how to use dotnetsdk."
|
||||
$script:exitCode = -1
|
||||
}
|
||||
if ($Wait) {
|
||||
Console-Write "Press any key to continue ..."
|
||||
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
|
||||
}
|
||||
|
||||
# If the user specified an output variable, push the value up to the parent scope
|
||||
if($OutputVariable) {
|
||||
Set-Variable $OutputVariable $script:capturedOut -Scope 1
|
||||
}
|
||||
|
||||
exit $script:exitCode
|
||||
416
dotnetsdk.sh
416
dotnetsdk.sh
|
|
@ -1,416 +0,0 @@
|
|||
# dotnetsdk.sh
|
||||
# Source this file from your .bash-profile or script to use
|
||||
|
||||
_dotnetsdk_has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
if _dotnetsdk_has "unsetopt"; then
|
||||
unsetopt nomatch 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -z "$DOTNET_USER_HOME" ]; then
|
||||
eval DOTNET_USER_HOME=~/.dotnet
|
||||
fi
|
||||
|
||||
DOTNET_USER_PACKAGES="$DOTNET_USER_HOME/runtimes"
|
||||
if [ -z "$DOTNET_FEED" ]; then
|
||||
DOTNET_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
|
||||
fi
|
||||
|
||||
_dotnetsdk_find_latest() {
|
||||
local platform="mono"
|
||||
|
||||
if ! _dotnetsdk_has "curl"; then
|
||||
echo 'dotnetsdk needs curl to proceed.' >&2;
|
||||
return 1
|
||||
fi
|
||||
|
||||
local url="$DOTNET_FEED/GetUpdates()?packageIds=%27dotnet-$platform%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
|
||||
xml="$(curl $url 2>/dev/null)"
|
||||
echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1
|
||||
version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')"
|
||||
echo $version
|
||||
}
|
||||
|
||||
_dotnetsdk_strip_path() {
|
||||
echo "$1" | sed -e "s#$DOTNET_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$DOTNET_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$DOTNET_USER_PACKAGES/[^/]*$2[^:]*##g"
|
||||
}
|
||||
|
||||
_dotnetsdk_prepend_path() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "$2"
|
||||
else
|
||||
echo "$2:$1"
|
||||
fi
|
||||
}
|
||||
|
||||
_dotnetsdk_package_version() {
|
||||
local runtimeFullName="$1"
|
||||
echo "$runtimeFullName" | sed "s/[^.]*.\(.*\)/\1/"
|
||||
}
|
||||
|
||||
_dotnetsdk_package_name() {
|
||||
local runtimeFullName="$1"
|
||||
echo "$runtimeFullName" | sed "s/\([^.]*\).*/\1/"
|
||||
}
|
||||
|
||||
_dotnetsdk_package_runtime() {
|
||||
local runtimeFullName="$1"
|
||||
echo "$runtimeFullName" | sed "s/DNX-\([^.-]*\).*/\1/"
|
||||
}
|
||||
|
||||
_dotnetsdk_download() {
|
||||
local runtimeFullName="$1"
|
||||
local runtimeFolder="$2"
|
||||
|
||||
local pkgName=$(_dotnetsdk_package_name "$runtimeFullName")
|
||||
local pkgVersion=$(_dotnetsdk_package_version "$runtimeFullName")
|
||||
local url="$DOTNET_FEED/package/$pkgName/$pkgVersion"
|
||||
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
|
||||
|
||||
if [ -e "$runtimeFolder" ]; then
|
||||
echo "$runtimeFullName already installed."
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Downloading $runtimeFullName from $DOTNET_FEED"
|
||||
|
||||
if ! _dotnetsdk_has "curl"; then
|
||||
echo "dotnetsdk needs curl to proceed." >&2;
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$runtimeFolder" > /dev/null 2>&1
|
||||
|
||||
local httpResult=$(curl -L -D - "$url" -o "$runtimeFile" 2>/dev/null | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
|
||||
|
||||
[[ $httpResult == "404" ]] && echo "$runtimeFullName was not found in repository $DOTNET_FEED" && return 1
|
||||
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $runtimeFullName from $DOTNET_FEED" && return 1
|
||||
|
||||
_dotnetsdk_unpack $runtimeFile $runtimeFolder
|
||||
return $?
|
||||
}
|
||||
|
||||
_dotnetsdk_unpack() {
|
||||
local runtimeFile="$1"
|
||||
local runtimeFolder="$2"
|
||||
|
||||
echo "Installing to $runtimeFolder"
|
||||
|
||||
if ! _dotnetsdk_has "unzip"; then
|
||||
echo "dotnetsdk needs unzip to proceed." >&2;
|
||||
return 1
|
||||
fi
|
||||
|
||||
unzip $runtimeFile -d $runtimeFolder > /dev/null 2>&1
|
||||
|
||||
[ -e "$runtimeFolder/[Content_Types].xml" ] && rm "$runtimeFolder/[Content_Types].xml"
|
||||
|
||||
[ -e "$runtimeFolder/_rels/" ] && rm -rf "$runtimeFolder/_rels/"
|
||||
|
||||
[ -e "$runtimeFolder/package/" ] && rm -rf "$runtimeFolder/_package/"
|
||||
|
||||
#Set shell commands as executable
|
||||
find "$runtimeFolder/bin/" -type f \
|
||||
-exec sh -c "head -c 11 {} | grep '/bin/bash' > /dev/null" \; -print | xargs chmod 775
|
||||
}
|
||||
|
||||
_dotnetsdk_requested_version_or_alias() {
|
||||
local versionOrAlias="$1"
|
||||
local runtimeBin=$(_dotnetsdk_locate_runtime_bin_from_full_name "$versionOrAlias")
|
||||
|
||||
# If the name specified is an existing package, just use it as is
|
||||
if [ -n "$runtimeBin" ]; then
|
||||
echo "$versionOrAlias"
|
||||
else
|
||||
if [ -e "$DOTNET_USER_HOME/alias/$versionOrAlias.alias" ]; then
|
||||
local runtimeFullName=$(cat "$DOTNET_USER_HOME/alias/$versionOrAlias.alias")
|
||||
local pkgName=$(echo $runtimeFullName | sed "s/\([^.]*\).*/\1/")
|
||||
local pkgVersion=$(echo $runtimeFullName | sed "s/[^.]*.\(.*\)/\1/")
|
||||
local pkgPlatform=$(echo "$pkgName" | sed "s/dotnet-\([^.-]*\).*/\1/")
|
||||
else
|
||||
local pkgVersion=$versionOrAlias
|
||||
local pkgPlatform="mono"
|
||||
fi
|
||||
|
||||
echo "dotnet-$pkgPlatform.$pkgVersion"
|
||||
fi
|
||||
}
|
||||
|
||||
# This will be more relevant if we support global installs
|
||||
_dotnetsdk_locate_runtime_bin_from_full_name() {
|
||||
local runtimeFullName=$1
|
||||
[ -e "$DOTNET_USER_PACKAGES/$runtimeFullName/bin" ] && echo "$DOTNET_USER_PACKAGES/$runtimeFullName/bin" && return
|
||||
}
|
||||
|
||||
dotnetsdk()
|
||||
{
|
||||
if [ $# -lt 1 ]; then
|
||||
dotnetsdk help
|
||||
return
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"help" )
|
||||
echo ""
|
||||
echo ".NET SDK Manager - Build 10305"
|
||||
echo ""
|
||||
echo "USAGE: dotnetsdk <command> [options]"
|
||||
echo ""
|
||||
echo "dotnetsdk upgrade"
|
||||
echo "install latest .NET Runtime from feed"
|
||||
echo "add .NET Runtime bin to path of current command line"
|
||||
echo "set installed version as default"
|
||||
echo ""
|
||||
echo "dotnetsdk install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p -persistent]"
|
||||
echo "<semver>|<alias> install requested .NET Runtime from feed"
|
||||
echo "<nupkg> install requested .NET Runtime from local package on filesystem"
|
||||
echo "latest install latest version of .NET Runtime from feed"
|
||||
echo "-a|-alias <alias> set alias <alias> for requested .NET Runtime on install"
|
||||
echo "-p -persistent set installed version as default"
|
||||
echo "add .NET Runtime bin to path of current command line"
|
||||
echo ""
|
||||
echo "dotnetsdk use <semver>|<alias>|<package>|none [-p -persistent]"
|
||||
echo "<semver>|<alias>|<package> add .NET Runtime bin to path of current command line "
|
||||
echo "none remove .NET Runtime bin from path of current command line"
|
||||
echo "-p -persistent set selected version as default"
|
||||
echo ""
|
||||
echo "dotnetsdk list"
|
||||
echo "list .NET Runtime versions installed "
|
||||
echo ""
|
||||
echo "dotnetsdk alias"
|
||||
echo "list .NET Runtime aliases which have been defined"
|
||||
echo ""
|
||||
echo "dotnetsdk alias <alias>"
|
||||
echo "display value of the specified alias"
|
||||
echo ""
|
||||
echo "dotnetsdk alias <alias> <semver>|<alias>|<package>"
|
||||
echo "<alias> the name of the alias to set"
|
||||
echo "<semver>|<alias>|<package> the .NET Runtime version to set the alias to. Alternatively use the version of the specified alias"
|
||||
echo ""
|
||||
echo "dotnetsdk unalias <alias>"
|
||||
echo "remove the specified alias"
|
||||
echo ""
|
||||
;;
|
||||
|
||||
"upgrade" )
|
||||
[ $# -ne 1 ] && dotnetsdk help && return
|
||||
dotnetsdk install latest -p
|
||||
;;
|
||||
|
||||
"install" )
|
||||
[ $# -lt 2 ] && dotnetsdk help && return
|
||||
shift
|
||||
local persistent=
|
||||
local versionOrAlias=
|
||||
local alias=
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
|
||||
local persistent="-p"
|
||||
elif [[ $1 == "-a" || $1 == "-alias" ]]; then
|
||||
local alias=$2
|
||||
shift
|
||||
elif [[ -n $1 ]]; then
|
||||
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && dotnetsdk help && return 1
|
||||
local versionOrAlias=$1
|
||||
fi
|
||||
shift
|
||||
done
|
||||
if [[ "$versionOrAlias" == "latest" ]]; then
|
||||
echo "Determining latest version"
|
||||
versionOrAlias=$(_dotnetsdk_find_latest)
|
||||
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DOTNET_FEED" && return 1
|
||||
echo "Latest version is $versionOrAlias"
|
||||
fi
|
||||
if [[ "$versionOrAlias" == *.nupkg ]]; then
|
||||
local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
|
||||
local runtimeVersion=$(_dotnetsdk_package_version "$runtimeFullName")
|
||||
local runtimeFolder="$DOTNET_USER_PACKAGES/$runtimeFullName"
|
||||
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
|
||||
|
||||
if [ -e "$runtimeFolder" ]; then
|
||||
echo "$runtimeFullName already installed"
|
||||
else
|
||||
mkdir "$runtimeFolder" > /dev/null 2>&1
|
||||
cp -a "$versionOrAlias" "$runtimeFile"
|
||||
_dotnetsdk_unpack "$runtimeFile" "$runtimeFolder"
|
||||
[[ $? == 1 ]] && return 1
|
||||
fi
|
||||
dotnetsdk use "$runtimeVersion" "$persistent"
|
||||
[[ -n $alias ]] && dotnetsdk alias "$alias" "$runtimeVersion"
|
||||
else
|
||||
local runtimeFullName="$(_dotnetsdk_requested_version_or_alias $versionOrAlias)"
|
||||
local runtimeFolder="$DOTNET_USER_PACKAGES/$runtimeFullName"
|
||||
_dotnetsdk_download "$runtimeFullName" "$runtimeFolder"
|
||||
[[ $? == 1 ]] && return 1
|
||||
dotnetsdk use "$versionOrAlias" "$persistent"
|
||||
[[ -n $alias ]] && dotnetsdk alias "$alias" "$versionOrAlias"
|
||||
fi
|
||||
;;
|
||||
|
||||
"use" )
|
||||
[ $# -gt 3 ] && dotnetsdk help && return
|
||||
[ $# -lt 2 ] && dotnetsdk help && return
|
||||
|
||||
shift
|
||||
local persistent=
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
|
||||
local persistent="true"
|
||||
elif [[ -n $1 ]]; then
|
||||
local versionOrAlias=$1
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ $versionOrAlias == "none" ]]; then
|
||||
echo "Removing .NET Runtime from process PATH"
|
||||
# Strip other version from PATH
|
||||
PATH=$(_dotnetsdk_strip_path "$PATH" "/bin")
|
||||
|
||||
if [[ -n $persistent && -e "$DOTNET_USER_HOME/alias/default.alias" ]]; then
|
||||
echo "Setting default .NET Runtime to none"
|
||||
rm "$DOTNET_USER_HOME/alias/default.alias"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
local runtimeFullName=$(_dotnetsdk_requested_version_or_alias "$versionOrAlias")
|
||||
local runtimeBin=$(_dotnetsdk_locate_runtime_bin_from_full_name "$runtimeFullName")
|
||||
|
||||
if [[ -z $runtimeBin ]]; then
|
||||
echo "Cannot find $runtimeFullName, do you need to run 'dotnetsdk install $versionOrAlias'?"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Adding" $runtimeBin "to process PATH"
|
||||
|
||||
PATH=$(_dotnetsdk_strip_path "$PATH" "/bin")
|
||||
PATH=$(_dotnetsdk_prepend_path "$PATH" "$runtimeBin")
|
||||
|
||||
if [[ -n $persistent ]]; then
|
||||
local runtimeVersion=$(_dotnetsdk_package_version "$runtimeFullName")
|
||||
dotnetsdk alias default "$runtimeVersion"
|
||||
fi
|
||||
;;
|
||||
|
||||
"alias" )
|
||||
[[ $# -gt 3 ]] && dotnetsdk help && return
|
||||
|
||||
[[ ! -e "$DOTNET_USER_HOME/alias/" ]] && mkdir "$DOTNET_USER_HOME/alias/" > /dev/null
|
||||
|
||||
if [[ $# == 1 ]]; then
|
||||
echo ""
|
||||
local format="%-20s %s\n"
|
||||
printf "$format" "Alias" "Name"
|
||||
printf "$format" "-----" "----"
|
||||
if [ -d "$DOTNET_USER_HOME/alias" ]; then
|
||||
for _dotnetsdk_file in $(find "$DOTNET_USER_HOME/alias" -name *.alias); do
|
||||
local alias="$(basename $_dotnetsdk_file | sed 's/\.alias//')"
|
||||
local name="$(cat $_dotnetsdk_file)"
|
||||
printf "$format" "$alias" "$name"
|
||||
done
|
||||
fi
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
local name="$2"
|
||||
|
||||
if [[ $# == 2 ]]; then
|
||||
[[ ! -e "$DOTNET_USER_HOME/alias/$name.alias" ]] && echo "There is no alias called '$name'" && return
|
||||
cat "$DOTNET_USER_HOME/alias/$name.alias"
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
local runtimeFullName=$(_dotnetsdk_requested_version_or_alias "$3")
|
||||
|
||||
[[ ! -d "$DOTNET_USER_PACKAGES/$runtimeFullName" ]] && echo "$runtimeFullName is not an installed .NET Runtime version" && return 1
|
||||
|
||||
local action="Setting"
|
||||
[[ -e "$DOTNET_USER_HOME/alias/$name.alias" ]] && action="Updating"
|
||||
echo "$action alias '$name' to '$runtimeFullName'"
|
||||
echo "$runtimeFullName" > "$DOTNET_USER_HOME/alias/$name.alias"
|
||||
;;
|
||||
|
||||
"unalias" )
|
||||
[[ $# -ne 2 ]] && dotnetsdk help && return
|
||||
|
||||
local name=$2
|
||||
local aliasPath="$DOTNET_USER_HOME/alias/$name.alias"
|
||||
[[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1
|
||||
echo "Removing alias $name"
|
||||
rm "$aliasPath" >> /dev/null 2>&1
|
||||
;;
|
||||
|
||||
"list" )
|
||||
[[ $# -gt 2 ]] && dotnetsdk help && return
|
||||
|
||||
[[ ! -d $DOTNET_USER_PACKAGES ]] && echo ".NET Runtime is not installed." && return 1
|
||||
|
||||
local searchGlob="dotnet-*"
|
||||
if [ $# == 2 ]; then
|
||||
local versionOrAlias=$2
|
||||
local searchGlob=$(_dotnetsdk_requested_version_or_alias "$versionOrAlias")
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Separate empty array declaration from initialization
|
||||
# to avoid potential ZSH error: local:217: maximum nested function level reached
|
||||
local arr
|
||||
arr=()
|
||||
|
||||
# Z shell array-index starts at one.
|
||||
local i=1
|
||||
local format="%-20s %s\n"
|
||||
if [ -d "$DOTNET_USER_HOME/alias" ]; then
|
||||
for _dotnetsdk_file in $(find "$DOTNET_USER_HOME/alias" -name *.alias); do
|
||||
arr[$i]="$(basename $_dotnetsdk_file | sed 's/\.alias//')/$(cat $_dotnetsdk_file)"
|
||||
let i+=1
|
||||
done
|
||||
fi
|
||||
|
||||
local formatString="%-6s %-20s %-7s %-20s %s\n"
|
||||
printf "$formatString" "Active" "Version" "Runtime" "Location" "Alias"
|
||||
printf "$formatString" "------" "-------" "-------" "--------" "-----"
|
||||
|
||||
local formattedHome=`(echo $DOTNET_USER_PACKAGES | sed s=$HOME=~=g)`
|
||||
for f in $(find $DOTNET_USER_PACKAGES -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;); do
|
||||
local active=""
|
||||
[[ $PATH == *"$DOTNET_USER_PACKAGES/$f/bin"* ]] && local active=" *"
|
||||
local pkgName=$(_dotnetsdk_package_runtime "$f")
|
||||
local pkgVersion=$(_dotnetsdk_package_version "$f")
|
||||
|
||||
local alias=""
|
||||
local delim=""
|
||||
for i in "${arr[@]}"; do
|
||||
temp="dotnet-$pkgName.$pkgVersion"
|
||||
temp2="dotnet-$pkgName-x86.$pkgVersion"
|
||||
if [[ ${i#*/} == $temp || ${i#*/} == $temp2 ]]; then
|
||||
alias+="$delim${i%/*}"
|
||||
delim=", "
|
||||
fi
|
||||
done
|
||||
|
||||
printf "$formatString" "$active" "$pkgVersion" "$pkgName" "$formattedHome" "$alias"
|
||||
[[ $# == 2 ]] && echo "" && return 0
|
||||
done
|
||||
|
||||
echo ""
|
||||
[[ $# == 2 ]] && echo "$versionOrAlias not found" && return 1
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown command $1"
|
||||
return 1
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
dotnetsdk list default >/dev/null && dotnetsdk use default >/dev/null || true
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"webroot": "wwwroot",
|
||||
"exclude": [
|
||||
"wwwroot"
|
||||
],
|
||||
"packExclude": [
|
||||
"**.kproj",
|
||||
"**.user",
|
||||
"**.vspscc"
|
||||
],
|
||||
"dependencies": {
|
||||
"Kestrel": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Diagnostics": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4*"
|
||||
},
|
||||
"commands": {
|
||||
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
|
||||
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 303 KiB After Width: | Height: | Size: 303 KiB |
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"webroot": "wwwroot",
|
||||
"exclude": [
|
||||
"wwwroot"
|
||||
],
|
||||
"packExclude": [
|
||||
"**.kproj",
|
||||
"**.user",
|
||||
"**.vspscc"
|
||||
],
|
||||
"dependencies": {
|
||||
"Kestrel": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Diagnostics": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Hosting": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4-*",
|
||||
"Microsoft.AspNet.StaticFiles": "1.0.0-beta4-*"
|
||||
},
|
||||
"commands": {
|
||||
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
|
||||
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 303 KiB After Width: | Height: | Size: 303 KiB |
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>d4f684c8-b6a4-45f0-aca0-0d95632ff946</ProjectGuid>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("Hello World");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"dependencies": {
|
||||
|
||||
},
|
||||
"commands": {
|
||||
"ConsoleApp": "ConsoleApp"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"System.Console": "4.0.0-beta-*"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
using Microsoft.AspNet.Mvc;
|
||||
using MvcSample.Web.Models;
|
||||
|
||||
namespace MvcSample.Web
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View(CreateUser());
|
||||
}
|
||||
|
||||
public User CreateUser()
|
||||
{
|
||||
User user = new User()
|
||||
{
|
||||
Name = "My name",
|
||||
Address = "My address"
|
||||
};
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>78627bb3-851e-4c1a-91c0-629fc7c15f8f</ProjectGuid>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<DevelopmentServerPort>26425</DevelopmentServerPort>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MvcSample.Web.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
[Required]
|
||||
[MinLength(4)]
|
||||
public string Name { get; set; }
|
||||
public string Address { get; set; }
|
||||
public int Age { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNET_ENV": "Development"
|
||||
}
|
||||
},
|
||||
"kestrel": {
|
||||
"commandName": "kestrel",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "http://localhost:5004"
|
||||
},
|
||||
"web": {
|
||||
"commandName": "web",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "http://localhost:5001"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace HelloMvc
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseErrorPage();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
|
||||
app.UseWelcomePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
@using MvcSample.Web.Models
|
||||
@model User
|
||||
@{
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "Home Page";
|
||||
string helloClass = null;
|
||||
}
|
||||
|
||||
<div class="jumbotron">
|
||||
<h1>ASP.NET</h1>
|
||||
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
|
||||
<p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more »</a></p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<h3 title="@Model.Name" class="@helloClass">Hello @Model.Name!</h3>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>@ViewBag.Title - My ASP.NET Application</title>
|
||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/">Home</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container body-content">
|
||||
@RenderBody()
|
||||
<hr />
|
||||
<address>
|
||||
@if (@Model != null)
|
||||
{
|
||||
@Model.Address
|
||||
}
|
||||
</address>
|
||||
<footer>
|
||||
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 303 KiB |
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>8d4b2ab5-c2d2-4ee0-b751-f4126c7d0539</ProjectGuid>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<DevelopmentServerPort>26235</DevelopmentServerPort>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNET_ENV": "Development"
|
||||
}
|
||||
},
|
||||
"kestrel": {
|
||||
"commandName": "kestrel",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "http://localhost:5004"
|
||||
},
|
||||
"web": {
|
||||
"commandName": "web",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "http://localhost:5001"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using Microsoft.AspNet.Builder;
|
||||
|
||||
namespace HelloWeb
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseStaticFiles();
|
||||
app.UseWelcomePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 303 KiB |
Loading…
Reference in New Issue