Skip to content

Commit 4e16cfd

Browse files
authored
Use LogErrorFromException when FindAssembliesWithReferencesTo throws (dotnet/razor#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 dotnet/razor@87c12a1
1 parent 19d9dbc commit 4e16cfd

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/Razor/Microsoft.NET.Sdk.Razor/src/ResolveAssemblyWithReferences.cs renamed to src/Razor/Microsoft.NET.Sdk.Razor/src/FindAssembliesWithReferencesTo.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using System.Reflection;
@@ -45,9 +46,15 @@ public override bool Execute()
4546
var targetAssemblyNames = TargetAssemblyNames.Select(s => s.ItemSpec).ToList();
4647

4748
var provider = new ReferenceResolver(targetAssemblyNames, referenceItems);
48-
var assemblyNames = provider.ResolveAssemblies();
49-
50-
ResolvedAssemblies = assemblyNames.ToArray();
49+
try
50+
{
51+
var assemblyNames = provider.ResolveAssemblies();
52+
ResolvedAssemblies = assemblyNames.ToArray();
53+
}
54+
catch (Exception ex)
55+
{
56+
Log.LogErrorFromException(ex);
57+
}
5158

5259
return !Log.HasLoggedErrors;
5360
}

src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.MvcApplicationPartsDiscovery.targets

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Copyright (c) .NET Foundation. All rights reserved.
1717
Condition="'$(RazorSdkBuildTasksAssembly)' != ''" />
1818

1919
<PropertyGroup>
20-
<GenerateMvcApplicationPartsAttribute Condition="'$(GenerateMvcApplicationPartsAssemblyAttributes)' == '' AND '$(OutputType)' == 'Exe'">true</GenerateMvcApplicationPartsAttribute>
20+
<GenerateMvcApplicationPartsAssemblyAttributes Condition="'$(GenerateMvcApplicationPartsAssemblyAttributes)' == '' AND '$(OutputType)' == 'Exe'">true</GenerateMvcApplicationPartsAssemblyAttributes>
2121

22-
<CoreCompileDependsOn Condition="'$(GenerateMvcApplicationPartsAttribute)' == 'true' AND '$(DesignTimeBuild)' != 'true'">
22+
<CoreCompileDependsOn Condition="'$(GenerateMvcApplicationPartsAssemblyAttributes)' == 'true' AND '$(DesignTimeBuild)' != 'true'">
2323
_DiscoverMvcApplicationParts;
2424
$(CoreCompileDependsOn);
2525
</CoreCompileDependsOn>

src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/ApplicationPartDiscoveryIntegrationTest.cs

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ private async Task Build_ProjectWithDependencyThatReferencesMvc_AddsAttribute(MS
3737
Assert.AssemblyHasAttribute(result, Path.Combine(OutputPath, "AppWithP2PReference.dll"), "Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute");
3838
}
3939

40+
[Fact]
41+
[InitializeTestProject("AppWithP2PReference", additionalProjects: "ClassLibrary")]
42+
public async Task Build_ProjectWithDependencyThatReferencesMvc_DoesNotGenerateAttributeIfFlagIsReset()
43+
{
44+
var result = await DotnetMSBuild("Build /p:GenerateMvcApplicationPartsAssemblyAttributes=false");
45+
46+
Assert.BuildPassed(result);
47+
48+
Assert.FileDoesNotExist(result, IntermediateOutputPath, "AppWithP2PReference.MvcApplicationPartsAssemblyInfo.cs");
49+
}
50+
4051
[Fact]
4152
[InitializeTestProject("SimpleMvc")]
4253
public async Task Build_ProjectWithoutMvcReferencingDependencies_DoesNotGenerateAttribute()

0 commit comments

Comments
 (0)