Use LogErrorFromException when FindAssembliesWithReferencesTo throws (dotnet/aspnetcore-tooling#702)

Currently FindAssembliesWithReferencesTo produces a stacktrace when P2P builds fail - for instance
if the referenced project has a compiler error. This changes it to use LogErrorFromException.

In addition, there was a typo in the property that disabled the feature.

Fixes https://github.com/aspnet/AspNetCore/issues/11226\n\nCommit migrated from 87c12a116c
This commit is contained in:
Pranav K 2019-06-26 11:18:54 -07:00 committed by GitHub
parent 19d9dbcd43
commit 4e16cfd4da
3 changed files with 23 additions and 5 deletions

View File

@ -1,6 +1,7 @@
// 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.Collections.Generic;
using System.Linq;
using System.Reflection;
@ -45,9 +46,15 @@ namespace Microsoft.AspNetCore.Razor.Tasks
var targetAssemblyNames = TargetAssemblyNames.Select(s => s.ItemSpec).ToList();
var provider = new ReferenceResolver(targetAssemblyNames, referenceItems);
var assemblyNames = provider.ResolveAssemblies();
ResolvedAssemblies = assemblyNames.ToArray();
try
{
var assemblyNames = provider.ResolveAssemblies();
ResolvedAssemblies = assemblyNames.ToArray();
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
}
return !Log.HasLoggedErrors;
}

View File

@ -17,9 +17,9 @@ Copyright (c) .NET Foundation. All rights reserved.
Condition="'$(RazorSdkBuildTasksAssembly)' != ''" />
<PropertyGroup>
<GenerateMvcApplicationPartsAttribute Condition="'$(GenerateMvcApplicationPartsAssemblyAttributes)' == '' AND '$(OutputType)' == 'Exe'">true</GenerateMvcApplicationPartsAttribute>
<GenerateMvcApplicationPartsAssemblyAttributes Condition="'$(GenerateMvcApplicationPartsAssemblyAttributes)' == '' AND '$(OutputType)' == 'Exe'">true</GenerateMvcApplicationPartsAssemblyAttributes>
<CoreCompileDependsOn Condition="'$(GenerateMvcApplicationPartsAttribute)' == 'true' AND '$(DesignTimeBuild)' != 'true'">
<CoreCompileDependsOn Condition="'$(GenerateMvcApplicationPartsAssemblyAttributes)' == 'true' AND '$(DesignTimeBuild)' != 'true'">
_DiscoverMvcApplicationParts;
$(CoreCompileDependsOn);
</CoreCompileDependsOn>

View File

@ -37,6 +37,17 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.AssemblyHasAttribute(result, Path.Combine(OutputPath, "AppWithP2PReference.dll"), "Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute");
}
[Fact]
[InitializeTestProject("AppWithP2PReference", additionalProjects: "ClassLibrary")]
public async Task Build_ProjectWithDependencyThatReferencesMvc_DoesNotGenerateAttributeIfFlagIsReset()
{
var result = await DotnetMSBuild("Build /p:GenerateMvcApplicationPartsAssemblyAttributes=false");
Assert.BuildPassed(result);
Assert.FileDoesNotExist(result, IntermediateOutputPath, "AppWithP2PReference.MvcApplicationPartsAssemblyInfo.cs");
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_ProjectWithoutMvcReferencingDependencies_DoesNotGenerateAttribute()