dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

VB.Net SDK Project fails to compile when two resx file exists with the same name in different namespaces #5469

Closed elachlan closed 3 years ago

elachlan commented 4 years ago

Steps to reproduce

Have a VB.Net winforms project using SDK project type. The project should include two forms with the same name in separate namespaces. Each form should have its icon set, so that it creates a resource file.

This isn't an issue for C#.

See Attached zip: VB: TestApp2.zip C#: TestApp3.zip

Error:

MSB3577: Two output file names resolved to the same output path: "obj\Debug\net472\TestApp2.Edit.resources"

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets

The code that the error points you to is line 3036 in Microsoft.Common.CurrentVersion.targets which is situated in the CoreResGen section: https://github.com/microsoft/msbuild/blob/e2a33003170b038bf0c2414df166b5409d4b9581/src/Tasks/Microsoft.Common.CurrentVersion.targets#L3035-L3064

I believe the error is raised from: https://github.com/microsoft/msbuild/blob/86d9494e446de002ea6a4f08d6fbd111b1041059/src/Tasks/GenerateResource.cs#L1462-L1491

The issue stems from the fact that in VB.Net the OutputResources are added without their namespaces: image

Where as the C# OutputResources are fully qualified: image

The names are transformed here using the EmbeddedResources ManifestResourceName, which seems to be broken in VB.NET: https://github.com/microsoft/msbuild/blob/e2a33003170b038bf0c2414df166b5409d4b9581/src/Tasks/Microsoft.Common.CurrentVersion.targets#L3050

elachlan commented 4 years ago

I wasn't sure where to raise it so i have also raised an issue in the dotnet/project-system: https://github.com/dotnet/project-system/issues/6312

elachlan commented 4 years ago

I have a report class library that doesn't have any forms and it also displayed the same issue.

elachlan commented 4 years ago

@rainersigwald sorry to bother you with this. I am wondering if this is enough information to go off of?

rainersigwald commented 4 years ago

@BenVillalobos can you take a look at this?

benvillalobos commented 4 years ago

@elachlan Thanks for such a detailed issue! There's a PR in the works now.

elachlan commented 4 years ago

@BenVillalobos Thanks for looking into it! Glad I was able to help :)

KathleenDollard commented 4 years ago

See https://github.com/microsoft/msbuild/pull/5477#pullrequestreview-450781160

elachlan commented 4 years ago

So essentially it can't be fixed/won't in msbuild?

Would the fix be in visual studio to have it add an entry to the project file with dependant upon for the form resource file?

Additionally might I suggest we add an explanation of the differences between C# and VB.net at the top of CreateVisualBasicManifestResourceName.cs?

elachlan commented 4 years ago

For the new SDK project format, would it not make sense for vb.net winforms projects to automatically include set dependant upon for its associated resource file (same name)? Visual Studio already recognises the resource file as a part of the form.

That way the project file isn't polluted unnecessarily with boilerplate definitions, which is the intention of the new format.

@KathleenDollard that wouldn't be a breaking change would it? Since its inline with what currently happens in the old project system?

benvillalobos commented 4 years ago

@elachlan unfortunately it doesn't seem obvious (at least to me) that there is a "fix" for this situation. Especially after discovering that vb.net doesn't account for subfolders by design. The way DependentUpon works at the moment is also by design, and this specific situation is an unfortunate side effect that we offer ways to get around (manually setting LogicalName, ManifestResourceName metadata, or changing the folder structure).

Though I do agree we should clarify the differences between the two files, as this info should be archived. If you'd like, please file an issue 🙂 otherwise I can do that in a day or two.

elachlan commented 4 years ago

I really appreciate all your help. I do not think the fix is in msbuild. But maybe in visual studio, to lighten the load of management.

I spent the last 4 days working to convert to an SDK project for two production winforms applications. I have to manually added entries for every form for the compile(vb/designer.vb) and embeddedresource tags(.resx) to get it to work.

Will visual studio be managing these entries in the project file in the future for VB.Net projects?

some of the issues I have had:

It really does need someone to investigate the use case thoroughly to iron out issues with the sdk format.

Thank you all for your help. You have done a great job.

benvillalobos commented 4 years ago

I'll have to defer to @KathleenDollard for your latest question.

Glad we got to a solution!