mirror of https://github.com/dotnet/tye.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace Tye
|
|
{
|
|
public static class TargetInstaller
|
|
{
|
|
public static void Install(string projectFilePath)
|
|
{
|
|
if (projectFilePath is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(projectFilePath));
|
|
}
|
|
|
|
var projectDirectory = Path.GetDirectoryName(projectFilePath);
|
|
var intermediateDirectory = Path.Combine(projectDirectory!, "obj");
|
|
|
|
Directory.CreateDirectory(intermediateDirectory);
|
|
|
|
var fileName = $"{Path.GetFileName(projectFilePath)}.Tye.targets";
|
|
var targetFilePath = Path.Combine(intermediateDirectory, fileName);
|
|
|
|
if (File.Exists(targetFilePath))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var toolType = typeof(TargetInstaller);
|
|
var toolAssembly = toolType.GetTypeInfo().Assembly;
|
|
var toolImportTargetsResourceName = $"Tye.Resources.Imports.targets";
|
|
|
|
using var stream = toolAssembly.GetManifestResourceStream(toolImportTargetsResourceName);
|
|
if (stream == null)
|
|
{
|
|
throw new CommandException("Failed to find resource. Valid names: " + string.Join(", ", toolAssembly.GetManifestResourceNames()));
|
|
}
|
|
|
|
var targetBytes = new byte[stream.Length];
|
|
stream.Read(targetBytes, 0, targetBytes.Length);
|
|
File.WriteAllBytes(targetFilePath, targetBytes);
|
|
}
|
|
}
|
|
}
|
|
|