Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit d9fe793

Browse files
author
N. Taylor Mullen
committed
Add support for net451 projects.
- Previous to this any net451 projects that Razor-tooling would attempt to load would explode. - We now dispatch to ourselves within a users output to ensure that all dependencies are matched up correctly. - Added framework/configuration options to enable dispatching to properly find where our counterpart exists in a projects output. - Renamed bin directory option to build base path. With dispatching logic VisualStudio can't easily determine the users RID which is required for an output path to dotnet. - Replaced `AssemblyLoadContext` logic with `Assembly.Load` since we now always invoke ourselves in an environment where `Assembly.Load` is accurate. This way logic in the desktop process and non-desktop processes are identical. - Broke the `ResolveTagHelpersCommand` into 3 pieces so we can determine dispatching logic at the Program.Main level. This was required to use pieces of the `DotnetToolDispatcher`. - We utilize DotnetToolDispatcher for dispatch logic, this also ensures that we never have mismatched references for dotnet-razor-tooling in tools/dependencies sections. - Worked around an issue in `ProjectDependenciesCommandFactory` where configuration isn't properly flowed from constructor to `Create` method: https://github.com/dotnet/cli/issues/2512 - Worked around an issue where binding redirects were not being created for executable desktop packages. This involved upping Newtonsoft.Json to 8.0.3: https://github.com/dotnet/cli/issues/2505 #55
1 parent 6a59d9d commit d9fe793

15 files changed

Lines changed: 344 additions & 253 deletions

src/dotnet-razor-tooling/Internal/AssemblyLoadContextTagHelperTypeResolver.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/dotnet-razor-tooling/Internal/AssemblyTagHelperDescriptorResolver.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Globalization;
7-
using System.Runtime.Loader;
87
using dotnet_razor_tooling;
98
using Microsoft.AspNetCore.Razor;
109
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
@@ -17,14 +16,9 @@ public class AssemblyTagHelperDescriptorResolver
1716
private readonly TagHelperDescriptorFactory _descriptorFactory = new TagHelperDescriptorFactory(designTime: true);
1817
private readonly TagHelperTypeResolver _tagHelperTypeResolver;
1918

20-
public AssemblyTagHelperDescriptorResolver(AssemblyLoadContext loadContext)
19+
public AssemblyTagHelperDescriptorResolver()
2120
{
22-
if (loadContext == null)
23-
{
24-
throw new ArgumentNullException(nameof(loadContext));
25-
}
26-
27-
_tagHelperTypeResolver = new AssemblyLoadContextTagHelperTypeResolver(loadContext);
21+
_tagHelperTypeResolver = new TagHelperTypeResolver();
2822
}
2923

3024
public static int DefaultProtocolVersion { get; } = 1;

src/dotnet-razor-tooling/Internal/ResolveProtocolCommand.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System;
55
using System.Globalization;
6+
using dotnet_razor_tooling;
7+
using Microsoft.DotNet.Cli.Utils;
68
using Microsoft.Extensions.CommandLineUtils;
79

810
namespace Microsoft.AspNetCore.Tooling.Razor.Internal
@@ -23,10 +25,20 @@ internal static void Register(CommandLineApplication app)
2325
{
2426
var pluginProtocol = AssemblyTagHelperDescriptorResolver.DefaultProtocolVersion;
2527
var clientProtocolString = clientProtocolArgument.Value;
26-
var clientProtocol = int.Parse(clientProtocolString);
28+
int clientProtocol;
29+
if (!int.TryParse(clientProtocolString, out clientProtocol))
30+
{
31+
Reporter.Error.WriteLine(
32+
string.Format(
33+
CultureInfo.CurrentCulture,
34+
Resources.CouldNotParseProvidedProtocol,
35+
clientProtocolString));
36+
return 1;
37+
}
38+
2739
var resolvedProtocol = ResolveProtocol(clientProtocol, pluginProtocol);
2840

29-
Console.WriteLine(resolvedProtocol.ToString(CultureInfo.InvariantCulture));
41+
Reporter.Output.WriteLine(resolvedProtocol.ToString(CultureInfo.InvariantCulture));
3042

3143
return 0;
3244
});

src/dotnet-razor-tooling/Internal/ResolveTagHelpersCommand.cs

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.AspNetCore.Razor;
7+
using Microsoft.AspNetCore.Razor.Compilation.TagHelpers;
8+
using Microsoft.DotNet.Cli.Utils;
9+
using Microsoft.Extensions.CommandLineUtils;
10+
using Newtonsoft.Json;
11+
12+
namespace Microsoft.AspNetCore.Tooling.Razor.Internal
13+
{
14+
public abstract class ResolveTagHelpersCommandBase
15+
{
16+
protected const string CommandName = "resolve-taghelpers";
17+
18+
protected CommandOption ProtocolOption { get; set; }
19+
20+
protected CommandArgument AssemblyNamesArgument { get; set; }
21+
22+
public static void Register<TResolveTagHelpersCommand>(CommandLineApplication app) where
23+
TResolveTagHelpersCommand : ResolveTagHelpersCommandBase, new()
24+
{
25+
var command = new TResolveTagHelpersCommand();
26+
command.Register(app);
27+
}
28+
29+
protected virtual void Configure(CommandLineApplication config)
30+
{
31+
}
32+
33+
protected abstract int OnExecute();
34+
35+
protected void ReportResults(IEnumerable<TagHelperDescriptor> descriptors, IEnumerable<RazorError> errors)
36+
{
37+
var resolvedResult = new ResolvedTagHelperDescriptorsResult
38+
{
39+
Descriptors = descriptors,
40+
Errors = errors
41+
};
42+
43+
var serializedResult = JsonConvert.SerializeObject(resolvedResult, Formatting.Indented);
44+
45+
Reporter.Output.WriteLine(serializedResult);
46+
}
47+
48+
protected void ReportError(string message)
49+
{
50+
var error = new RazorError(message, SourceLocation.Zero, length: 0);
51+
ReportResults(descriptors: null, errors: new[] { error });
52+
}
53+
54+
private void Register(CommandLineApplication app)
55+
{
56+
app.Command(CommandName, config =>
57+
{
58+
config.Description = "Resolves TagHelperDescriptors in the specified assembly(s).";
59+
config.HelpOption("-?|-h|--help");
60+
ProtocolOption = config.Option(
61+
"-p|--protocol",
62+
"Protocol to resolve TagHelperDescriptors with.",
63+
CommandOptionType.SingleValue);
64+
65+
Configure(config);
66+
67+
AssemblyNamesArgument = config.Argument(
68+
"[assemblyName]",
69+
"Assembly name to resolve TagHelperDescriptors in.",
70+
multipleValues: true);
71+
72+
config.OnExecute((Func<int>)OnExecute);
73+
});
74+
}
75+
76+
private class ResolvedTagHelperDescriptorsResult
77+
{
78+
public IEnumerable<TagHelperDescriptor> Descriptors { get; set; }
79+
80+
public IEnumerable<RazorError> Errors { get; set; }
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)