mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-20 07:35:10 +00:00
Add support for side by side installations of multiple .NET SDK versions
This commit is contained in:
parent
7df9f59802
commit
4cc87c6ba3
13
README.md
13
README.md
@ -90,6 +90,19 @@ build:
|
||||
dotnet-version: '3.1.100' # SDK Version to use.
|
||||
```
|
||||
|
||||
Or for multiple versions installed side by side:
|
||||
```
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOTNET_NOLOGO: true
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: '2.1.807,3.1.100'
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||
|
56
dist/index.js
vendored
56
dist/index.js
vendored
@ -7891,8 +7891,19 @@ function run() {
|
||||
}
|
||||
}
|
||||
if (version) {
|
||||
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
||||
yield dotnetInstaller.installDotnet();
|
||||
let toolPaths = new Array();
|
||||
let versions = version.split(',');
|
||||
console.log(`Specified .NET verions: ${versions}`);
|
||||
for (var currentVersion of versions) {
|
||||
console.log(`Installing .NET SDK ${currentVersion}...`);
|
||||
const dotnetInstaller = new installer.DotnetCoreInstaller(currentVersion);
|
||||
toolPaths.push(yield dotnetInstaller.installDotnet());
|
||||
}
|
||||
if (toolPaths.length > 0) {
|
||||
console.log(`Setting up SxS .NET SDK versions...`);
|
||||
const sxsInstall = new installer.SxSDotnetCoreInstaller(toolPaths);
|
||||
yield sxsInstall.setupSxs();
|
||||
}
|
||||
}
|
||||
const sourceUrl = core.getInput('source-url');
|
||||
const configFile = core.getInput('config-file');
|
||||
@ -17391,8 +17402,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DotnetCoreInstaller = exports.DotNetVersionInfo = void 0;
|
||||
exports.SxSDotnetCoreInstaller = exports.DotnetCoreInstaller = exports.DotNetVersionInfo = void 0;
|
||||
// Load tempDirectory before it gets wiped by tool-cache
|
||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
@ -17401,9 +17415,11 @@ const io = __importStar(__webpack_require__(1));
|
||||
const tc = __importStar(__webpack_require__(533));
|
||||
const hc = __webpack_require__(539);
|
||||
const fs_1 = __webpack_require__(747);
|
||||
const fs_2 = __webpack_require__(747);
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const semver = __importStar(__webpack_require__(280));
|
||||
const v4_1 = __importDefault(__webpack_require__(826));
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
if (!tempDirectory) {
|
||||
let baseLocation;
|
||||
@ -17526,6 +17542,7 @@ class DotnetCoreInstaller {
|
||||
core.exportVariable('DOTNET_ROOT', toolPath);
|
||||
// Prepend the tools path. instructs the agent to prepend for future tasks
|
||||
core.addPath(toolPath);
|
||||
return toolPath;
|
||||
});
|
||||
}
|
||||
getLocalTool(version) {
|
||||
@ -17781,6 +17798,39 @@ class DotnetCoreInstaller {
|
||||
}
|
||||
}
|
||||
exports.DotnetCoreInstaller = DotnetCoreInstaller;
|
||||
class SxSDotnetCoreInstaller {
|
||||
constructor(toolPaths) {
|
||||
this.toolPaths = toolPaths;
|
||||
this.cachedToolName = 'dncs';
|
||||
this.arch = 'x64';
|
||||
}
|
||||
setupSxs() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// create a temp dir
|
||||
const tempDirectory = process.env['RUNNER_TEMP'] || '';
|
||||
const dest = path.join(tempDirectory, v4_1.default());
|
||||
yield io.mkdirP(dest);
|
||||
console.log(`Setting up SxS .NET SDK installation in ${dest}...`);
|
||||
// copy all the SDK versions into a temporary SxS directory
|
||||
for (var toolPath of this.toolPaths) {
|
||||
console.log(`Setting up .NET SDK from ${toolPath}...`);
|
||||
let entries = fs_2.readdirSync(toolPath);
|
||||
for (var entry of entries) {
|
||||
yield io.cp(path.join(toolPath, entry), dest, { recursive: true, force: true });
|
||||
}
|
||||
;
|
||||
}
|
||||
// cache SxS directory as a tool
|
||||
let cachedDir = yield tc.cacheDir(dest, this.cachedToolName, 'sxs', this.arch);
|
||||
console.log(`SxS .NET SDK installation in ${cachedDir}`);
|
||||
// Need to set this so that .NET Core global tools find the right locations.
|
||||
core.exportVariable('DOTNET_ROOT', cachedDir);
|
||||
// Prepend the tools path. instructs the agent to prepend for future tasks
|
||||
core.addPath(cachedDir);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.SxSDotnetCoreInstaller = SxSDotnetCoreInstaller;
|
||||
const DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';
|
||||
|
||||
|
||||
|
@ -6,9 +6,11 @@ import * as io from '@actions/io';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import hc = require('@actions/http-client');
|
||||
import {chmodSync} from 'fs';
|
||||
import {readdirSync} from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import uuidV4 from 'uuid/v4'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
|
||||
@ -117,7 +119,7 @@ export class DotnetCoreInstaller {
|
||||
this.arch = 'x64';
|
||||
}
|
||||
|
||||
public async installDotnet() {
|
||||
public async installDotnet(): Promise<string> {
|
||||
// Check cache
|
||||
let toolPath: string = '';
|
||||
let osSuffixes = await this.detectMachineOS();
|
||||
@ -155,6 +157,8 @@ export class DotnetCoreInstaller {
|
||||
|
||||
// Prepend the tools path. instructs the agent to prepend for future tasks
|
||||
core.addPath(toolPath);
|
||||
|
||||
return toolPath;
|
||||
}
|
||||
|
||||
private getLocalTool(version: string): string {
|
||||
@ -495,5 +499,51 @@ export class DotnetCoreInstaller {
|
||||
private arch: string;
|
||||
}
|
||||
|
||||
export class SxSDotnetCoreInstaller {
|
||||
constructor(toolPaths: Array<string>) {
|
||||
this.toolPaths = toolPaths;
|
||||
this.cachedToolName = 'dncs';
|
||||
this.arch = 'x64';
|
||||
}
|
||||
|
||||
public async setupSxs() {
|
||||
// create a temp dir
|
||||
const tempDirectory = process.env['RUNNER_TEMP'] || '';
|
||||
const dest = path.join(tempDirectory, uuidV4());
|
||||
await io.mkdirP(dest)
|
||||
|
||||
console.log(`Setting up SxS .NET SDK installation in ${dest}...`);
|
||||
|
||||
// copy all the SDK versions into a temporary SxS directory
|
||||
for(var toolPath of this.toolPaths) {
|
||||
console.log(`Setting up .NET SDK from ${toolPath}...`);
|
||||
let entries = readdirSync(toolPath);
|
||||
for (var entry of entries) {
|
||||
await io.cp(path.join(toolPath, entry), dest, { recursive: true, force: true });
|
||||
};
|
||||
}
|
||||
|
||||
// cache SxS directory as a tool
|
||||
let cachedDir = await tc.cacheDir(
|
||||
dest,
|
||||
this.cachedToolName,
|
||||
'sxs',
|
||||
this.arch
|
||||
);
|
||||
|
||||
console.log(`SxS .NET SDK installation in ${cachedDir}`)
|
||||
|
||||
// Need to set this so that .NET Core global tools find the right locations.
|
||||
core.exportVariable('DOTNET_ROOT', cachedDir);
|
||||
|
||||
// Prepend the tools path. instructs the agent to prepend for future tasks
|
||||
core.addPath(cachedDir);
|
||||
}
|
||||
|
||||
private toolPaths: Array<string>;
|
||||
private cachedToolName: string;
|
||||
private arch: string;
|
||||
}
|
||||
|
||||
const DotNetCoreIndexUrl: string =
|
||||
'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as installer from './installer';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
@ -29,8 +30,19 @@ export async function run() {
|
||||
}
|
||||
|
||||
if (version) {
|
||||
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
||||
await dotnetInstaller.installDotnet();
|
||||
let toolPaths = new Array<string>();
|
||||
let versions = version.split(',');
|
||||
console.log(`Specified .NET verions: ${versions}`);
|
||||
for (var currentVersion of versions) {
|
||||
console.log(`Installing .NET SDK ${currentVersion}...`)
|
||||
const dotnetInstaller = new installer.DotnetCoreInstaller(currentVersion);
|
||||
toolPaths.push(await dotnetInstaller.installDotnet());
|
||||
}
|
||||
if (toolPaths.length > 0) {
|
||||
console.log(`Setting up SxS .NET SDK versions...`)
|
||||
const sxsInstall = new installer.SxSDotnetCoreInstaller(toolPaths);
|
||||
await sxsInstall.setupSxs();
|
||||
}
|
||||
}
|
||||
|
||||
const sourceUrl: string = core.getInput('source-url');
|
||||
|
Loading…
x
Reference in New Issue
Block a user