From 49f8ae28cff35893f88787e08191c90a67f4e561 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 10 Oct 2019 09:43:59 -0700 Subject: [PATCH 1/3] Add support for using a 3.0 SDK on VS 16.4. - The 3.0 SDK adds RazorDeclaration files to the compile list if they exist. If a user builds in VS and then does a project level operation (adding a property group or item group to their project file) a design time build will trigger for unrelated reasons and declaration files will be included as part of the C# compilation resulting in duplicate member errors. This change ensures that even if declaration files are added we then remove them to ensure we avoid those declaration additions. - One unfortunate aspect of this change is that declarations are added to the compile list for a brief moment resulting in errors and then are instantly removed in some situations. I say "some situations" because when this happens it is highly dependent on how / when the project system decides to perform a design time build. aspnet/AspNetCoredotnet/aspnetcore-tooling#14646 \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/b64c9317c42b6283dd28313e363012f7e6b56166 --- .../Microsoft.NET.Sdk.Razor.DesignTime.targets | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets index 0b27cfce4a..4d8e0b5c4d 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets +++ b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets @@ -47,6 +47,17 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + + + + - - + + + + + + + diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs index 2c86bf957c..fcb33acbf2 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs @@ -207,5 +207,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildOutputContainsLine(result, "Content: appsettings.json CopyToOutputDirectory=PreserveNewest CopyToPublishDirectory=PreserveNewest ExcludeFromSingleFile=true"); Assert.BuildOutputContainsLine(result, "Content: appsettings.Development.json CopyToOutputDirectory=PreserveNewest CopyToPublishDirectory=PreserveNewest ExcludeFromSingleFile=true"); } + + [Fact] + [InitializeTestProject("SimpleMvc")] + public async Task IntrospectJsonContentFiles_WithExcludeConfigFilesFromBuildOutputSet() + { + // Verifies that the fix for https://github.com/aspnet/AspNetCore/issues/14017 works. + var result = await DotnetMSBuild("_IntrospectContentItems", "/p:ExcludeConfigFilesFromBuildOutput=true"); + + Assert.BuildPassed(result); + var launchSettingsPath = Path.Combine("Properties", "launchSettings.json"); + Assert.BuildOutputContainsLine(result, $"Content: {launchSettingsPath} CopyToOutputDirectory= CopyToPublishDirectory=Never ExcludeFromSingleFile=true"); + Assert.BuildOutputContainsLine(result, "Content: appsettings.json CopyToOutputDirectory= CopyToPublishDirectory=PreserveNewest ExcludeFromSingleFile=true"); + Assert.BuildOutputContainsLine(result, "Content: appsettings.Development.json CopyToOutputDirectory= CopyToPublishDirectory=PreserveNewest ExcludeFromSingleFile=true"); + } } } From 163c09f9849258cc50e80277d319014936cb5b55 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 15 Oct 2019 10:29:33 -0700 Subject: [PATCH 3/3] Add support for partial component class editing -> refresh components. - We now do aggressive detection on the type of C# class that's being edited. In order to not impact C# scenarios we only do work if C# assets are available to us. Meaning, we inspect the old document and if that document has its' semantic model available we spend cycles to determine if it's a component. In the case that we find a C# component class that wasn't previously caught we enqueue an update. - Added several tests to ensure we enqueue and that we properly detect component classes. aspnet/AspNetCoredotnet/aspnetcore-tooling#14646 \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/d8b62e121fe748f2c581066ac451918e67bf77a5 --- .../src/ComponentDetectionConventions.cs | 28 +++++++++++++++++++ .../ComponentTagHelperDescriptorProvider.cs | 6 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs new file mode 100644 index 0000000000..214f9e36a4 --- /dev/null +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs @@ -0,0 +1,28 @@ +// 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; + +namespace Microsoft.CodeAnalysis.Razor +{ + internal static class ComponentDetectionConventions + { + public static bool IsComponent(INamedTypeSymbol symbol, INamedTypeSymbol icomponentSymbol) + { + if (symbol is null) + { + throw new ArgumentNullException(nameof(symbol)); + } + + if (icomponentSymbol is null) + { + throw new ArgumentNullException(nameof(icomponentSymbol)); + } + + return + symbol.DeclaredAccessibility == Accessibility.Public && + !symbol.IsAbstract && + symbol.AllInterfaces.Contains(icomponentSymbol); + } + } +} diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs index f160b53a90..ebc1947ca7 100644 --- a/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs @@ -573,10 +573,8 @@ namespace Microsoft.CodeAnalysis.Razor return false; } - return - symbol.DeclaredAccessibility == Accessibility.Public && - !symbol.IsAbstract && - symbol.AllInterfaces.Contains(_symbols.IComponent); + var isComponent = ComponentDetectionConventions.IsComponent(symbol, _symbols.IComponent); + return isComponent; } } }