Browse Source
This replaces the (dirty) technique of target-based injection with hosting MSBuild in process. This is a speedup of about 800ms per project for every project past the first one. Given that Tye is for microservices, hopefully you have more than one project.davidfowl/dependencies
7 changed files with 133 additions and 173 deletions
@ -1,8 +0,0 @@ |
|||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ImportGroup Condition=" '$(TargetFramework)' == '' AND '$(ExcludeRestorePackageImports)' != 'true' "> |
|||
<Import Project="$(TyeTargetLocation)\buildMultiTargeting\Tye.targets" Condition="'$(TyeTargetLocation)'!=''" /> |
|||
</ImportGroup> |
|||
<ImportGroup Condition=" '$(TargetFramework)' != '' AND '$(ExcludeRestorePackageImports)' != 'true' "> |
|||
<Import Project="$(TyeTargetLocation)\build\Tye.targets" Condition="'$(TyeTargetLocation)'!=''" /> |
|||
</ImportGroup> |
|||
</Project> |
|||
@ -1,48 +0,0 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using System.Reflection; |
|||
|
|||
namespace Microsoft.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); |
|||
} |
|||
} |
|||
} |
|||
@ -1,28 +0,0 @@ |
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
|
|||
<PropertyGroup> |
|||
<EvaluateTyeProjectInfoDependsOn> |
|||
$(EvaluateTyeProjectInfoDependsOn); |
|||
ResolveReferences; |
|||
ResolvePackageDependenciesDesignTime; |
|||
PrepareResources; |
|||
GetAssemblyAttributes; |
|||
</EvaluateTyeProjectInfoDependsOn> |
|||
</PropertyGroup> |
|||
|
|||
<Target Name="EvaluateTyeProjectInfo" DependsOnTargets="$(EvaluateTyeProjectInfoDependsOn)"> |
|||
<Error Message="TyeOutputFilePath was not specified." Condition="'$(TyeOutputFilePath)'==''" /> |
|||
|
|||
<PropertyGroup> |
|||
<_Frameworks>@(FrameworkReference, ',')</_Frameworks> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<_Lines Include="version=$(InformationalVersion)" /> |
|||
<_Lines Include="tfm=$(TargetFramework)" /> |
|||
<_Lines Include="frameworks=$(_Frameworks)" /> |
|||
</ItemGroup> |
|||
|
|||
<WriteLinesToFile File="$(TyeOutputFilePath)" Lines="@(_Lines)" Overwrite="true" /> |
|||
</Target> |
|||
|
|||
</Project> |
|||
@ -1,20 +0,0 @@ |
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<UsingTask TaskName="GetNearestTargetFramework" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" /> |
|||
|
|||
<Target Name="EvaluateTyeProjectInfo" DependsOnTargets="$(EvaluateTyeProjectInfoDependsOn)"> |
|||
<GetNearestTargetFramework |
|||
ReferringTargetFramework="netcoreapp3.0" |
|||
PossibleTargetFrameworks="$(TargetFrameworks)" |
|||
ProjectFilePath="$(MSBuildProjectFullPath)" |
|||
ContinueOnError="WarnAndContinue"> |
|||
<Output PropertyName="NearestTargetFramework" TaskParameter="NearestTargetFramework" /> |
|||
</GetNearestTargetFramework> |
|||
|
|||
<Error Text="Tye requires targeting netcoreapp3.0 and newer." Condition=" '$(NearestTargetFramework)' == '' " /> |
|||
|
|||
<MSBuild |
|||
Projects="$(MSBuildProjectFile)" |
|||
Targets="EvaluateTyeProjectInfo" |
|||
Properties="TargetFramework=$(NearestTargetFramework);OutputFile=$(OutputFile)" /> |
|||
</Target> |
|||
</Project> |
|||
Loading…
Reference in new issue