-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
OptionalWorkloadProvider.cs
48 lines (41 loc) · 2.03 KB
/
OptionalWorkloadProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Configurer;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Abstractions.TemplatePackage;
namespace Microsoft.DotNet.Tools.New
{
internal class OptionalWorkloadProvider : ITemplatePackageProvider
{
private readonly IEngineEnvironmentSettings _environmentSettings;
internal OptionalWorkloadProvider(ITemplatePackageProviderFactory factory, IEngineEnvironmentSettings settings)
{
Factory = factory;
_environmentSettings = settings;
}
public ITemplatePackageProviderFactory Factory { get; }
// To avoid warnings about unused, its implemented via add/remove
event Action ITemplatePackageProvider.TemplatePackagesChanged
{
add { }
remove { }
}
public Task<IReadOnlyList<ITemplatePackage>> GetAllTemplatePackagesAsync(CancellationToken cancellationToken)
{
var list = new List<TemplatePackage>();
var optionalWorkloadLocator = new TemplateLocator.TemplateLocator();
var sdkDirectory = Path.GetDirectoryName(typeof(DotnetFiles).Assembly.Location);
var sdkVersion = Path.GetFileName(sdkDirectory);
var dotnetRootPath = Path.GetDirectoryName(Path.GetDirectoryName(sdkDirectory));
string userProfileDir = CliFolderPathCalculator.DotnetUserProfileFolderPath;
var packages = optionalWorkloadLocator.GetDotnetSdkTemplatePackages(sdkVersion, dotnetRootPath, userProfileDir);
var fileSystem = _environmentSettings.Host.FileSystem;
foreach (var packageInfo in packages)
{
list.Add(new TemplatePackage(this, packageInfo.Path, fileSystem.GetLastWriteTimeUtc(packageInfo.Path)));
}
return Task.FromResult<IReadOnlyList<ITemplatePackage>>(list);
}
}
}