Make the BuildTools project consumable either as a NuGet package or locally by importing a .proj

This commit is contained in:
Steve Sanderson 2017-12-13 11:10:41 +00:00
parent c5a104c56d
commit 7390af1681
15 changed files with 87 additions and 45 deletions

View File

@ -4,10 +4,11 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<!-- In real apps, the following items would come from the Microsoft.Blazor package -->
<Import Project="..\..\src\Microsoft.Blazor.BuildTools\BlazorBuild.targets" />
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.Blazor\Microsoft.Blazor.csproj" />
</ItemGroup>
<!-- Local alternative to <PackageReference Include="Microsoft.Blazor.BuildTools" /> -->
<Import Project="..\..\src\Microsoft.Blazor.BuildTools\ReferenceFromSource.props" />
</Project>

View File

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<!-- In real apps, the following items would come from the Microsoft.Blazor package -->
<Import Project="..\..\src\Microsoft.Blazor.BuildTools\BlazorBuild.targets" />
<!-- Local alternative to <PackageReference Include="Microsoft.Blazor.BuildTools" /> -->
<Import Project="..\..\src\Microsoft.Blazor.BuildTools\ReferenceFromSource.props" />
</Project>

View File

@ -2,24 +2,16 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<!-- Local alternative to <RunArguments>blazor serve</RunArguments> -->
<RunArguments>run --project ..\..\src\Microsoft.Blazor.DevHost serve</RunArguments>
</PropertyGroup>
<!--
The following is an alternative to referencing Microsoft.Blazor.DevHost as
a <DotNetCliToolReference>. This is so that Microsoft.Blazor.DevHost gets
compiled from source.
-->
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.Blazor.DevHost\Microsoft.Blazor.DevHost.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
<PropertyGroup>
<RunArguments>run --project ..\..\src\Microsoft.Blazor.DevHost --no-build serve</RunArguments>
</PropertyGroup>
<!-- In real apps, the following items would come from the Microsoft.Blazor package -->
<Import Project="..\..\src\Microsoft.Blazor.BuildTools\BlazorBuild.targets" />
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.Blazor\Microsoft.Blazor.csproj" />
</ItemGroup>
<!-- Local alternative to <PackageReference Include="Microsoft.Blazor.BuildTools" /> -->
<Import Project="..\..\src\Microsoft.Blazor.BuildTools\ReferenceFromSource.props" />
</Project>

View File

@ -16,13 +16,12 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Blazor.BuildTools\Microsoft.Blazor.BuildTools.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Microsoft.Blazor.Common\Microsoft.Blazor.Common.csproj" />
</ItemGroup>
<Import Project="..\Microsoft.Blazor.BuildTools\local.props" />
<Import Project="..\Microsoft.Blazor.BuildTools\ReferenceFromSource.props" />
<Target Name="EnsureNpmRestored" Condition="!Exists('node_modules')">
<Exec Command="$(BlazorBuildTools) checknodejs -v 8.3.0" />
<Exec Command="$(BlazorBuildToolsExe) checknodejs -v 8.3.0" />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec Command="npm install" />
</Target>

View File

@ -0,0 +1 @@
/tools/

View File

@ -1,13 +0,0 @@
<Project>
<Target Name="GenerateBlazorMetadataFile" BeforeTargets="GetCopyToOutputDirectoryItems">
<PropertyGroup>
<BlazorMetadataFileName>$(AssemblyName).blazor.config</BlazorMetadataFileName>
<BlazorMetadataFilePath>$(TargetDir)$(BlazorMetadataFileName)</BlazorMetadataFilePath>
</PropertyGroup>
<WriteLinesToFile File="$(BlazorMetadataFilePath)" Lines="$(MSBuildProjectFullPath)" Overwrite="true" Encoding="Unicode"/>
<WriteLinesToFile File="$(BlazorMetadataFilePath)" Lines="$(OutDir)$(AssemblyName).dll" Overwrite="false" Encoding="Unicode"/>
<ItemGroup>
<ContentWithTargetPath Include="$(BlazorMetadataFilePath)" TargetPath="$(BlazorMetadataFileName)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>
</Project>

View File

@ -1,9 +1,12 @@
using Microsoft.Extensions.CommandLineUtils;
// 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 Microsoft.Extensions.CommandLineUtils;
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace Microsoft.Blazor.BuildTools.Cli
namespace Microsoft.Blazor.BuildTools.Cli.Commands
{
class CheckNodeJsInstalled
{

View File

@ -1,6 +1,8 @@
using Microsoft.Blazor.BuildTools.Cli;
// 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 Microsoft.Blazor.BuildTools.Cli.Commands;
using Microsoft.Extensions.CommandLineUtils;
using System;
namespace Microsoft.Blazor.BuildTools
{

View File

@ -3,8 +3,17 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
<OutDir>tools</OutDir>
<NoPackageAnalysis>true</NoPackageAnalysis>
<NuspecFile>Microsoft.Blazor.BuildTools.nuspec</NuspecFile>
<PackageVersion>0.0.1</PackageVersion>
<NuspecProperties>version=$(PackageVersion)</NuspecProperties>
</PropertyGroup>
<ItemGroup>
<None Remove="tools\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
</ItemGroup>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Microsoft.Blazor.BuildTools</id>
<version>$version$</version>
<authors>Microsoft</authors>
<description>Build tools for Blazor applications.</description>
</metadata>
<files>
<file src="_._" target="lib/netstandard1.0/" />
<file src="build\**" target="build" />
<file src="targets\**" target="targets" />
<file src="tools\**" target="tools" />
</files>
</package>

View File

@ -0,0 +1,19 @@
<Project>
<!--
Importing this file is equivalent to having:
<PackageDependency Include="Microsoft.Blazor.BuildTools" />
... except it's much more convenient when working in this repo, because it consumes the
BuildTools targets/exe directly without needing BuildTools to be packed into a .nupkg.
This is only intended for use by other projects in this repo.
-->
<Import Project="$(MSBuildThisFileDirectory)targets\All.targets" />
<ItemGroup>
<!-- Ensures BuildTools itself is built before the consuming project, but without
adding a runtime dependency on the .dll (to be equivalent to a <PackageDependency>
given that the packed version of BuildTools wouldn't add a .dll reference) -->
<ProjectReference Include="$(MSBuildThisFileDirectory)Microsoft.Blazor.BuildTools.csproj" ReferenceOutputAssembly="false" PrivateAssets="all" />
</ItemGroup>
</Project>

View File

@ -0,0 +1 @@


View File

@ -0,0 +1,3 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)..\..\targets\All.targets" />
</Project>

View File

@ -1,7 +0,0 @@
<Project>
<PropertyGroup>
<!-- To avoid repeatedly running up-to-date checks, rely on the project already being built. -->
<!-- For this to work, consumers will need to have a project reference to this project. -->
<BlazorBuildTools>dotnet run --no-build --project $(MSBuildThisFileDirectory)</BlazorBuildTools>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,17 @@
<Project>
<PropertyGroup>
<BlazorBuildToolsExe>dotnet $(MSBuildThisFileDirectory)..\tools\Microsoft.Blazor.BuildTools.dll</BlazorBuildToolsExe>
</PropertyGroup>
<Target Name="GenerateBlazorMetadataFile" BeforeTargets="GetCopyToOutputDirectoryItems">
<PropertyGroup>
<BlazorMetadataFileName>$(AssemblyName).blazor.config</BlazorMetadataFileName>
<BlazorMetadataFilePath>$(TargetDir)$(BlazorMetadataFileName)</BlazorMetadataFilePath>
</PropertyGroup>
<WriteLinesToFile File="$(BlazorMetadataFilePath)" Lines="$(MSBuildProjectFullPath)" Overwrite="true" Encoding="Unicode"/>
<WriteLinesToFile File="$(BlazorMetadataFilePath)" Lines="$(OutDir)$(AssemblyName).dll" Overwrite="false" Encoding="Unicode"/>
<ItemGroup>
<ContentWithTargetPath Include="$(BlazorMetadataFilePath)" TargetPath="$(BlazorMetadataFileName)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>
</Project>