Tye is a tool that makes developing, testing, and deploying microservices and distributed applications easier. Project Tye includes a local orchestrator to make developing microservices easier and the ability to deploy microservices to Kubernetes with min
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

// 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);
}
}
}