toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 260 forks source link

Incorrect template key when using constructor that takes assembly #311

Closed HakanL closed 4 years ago

HakanL commented 4 years ago

When I'm using the constructor of EmbeddedRazorProjectItem it's setting the template key to assembly.GetName().Name, which will not include the namespace. So the embedded views aren't found, and there's no way to override it.

I believe the issue is in this line: https://github.com/toddams/RazorLight/blob/744f545227083f17c63bcdef989bd5c2017ef53b/src/RazorLight/Razor/EmbeddedRazorProjectItem.cs#L23

There is also an issue that both the RootNamespace and Assembly properties that are exposed in the class have the setter exposed, but changing them won't do anything, the fullTemplateKey is only set in the constructor.

Suggested fixes:

  1. Fix the constructor that takes an assembly so the full namespace is included, or require the root namespace to be specified (and overriding the full key)
  2. Either remove the settings on the properties, or implement it properly so setting them will change the fullTemplateKey.
HakanL commented 4 years ago

I believe the current code worked when the name of the project (assembly) was the same name as the beginning of the namespace (RazorLight.Tests for example), but it fails when the project has a different name than the namespace (like name of project is SharedResources but the namespace is Company.Resources). I will submit a PR.

jzabroski commented 4 years ago

Can you please undo all the whitespace changes. It makes it hard to review? Otherwise, I am happy to accept this PR - your change sounds logical but I just dont want to push it with all these whitespace noise issues and possibly introduce something unexpected.

Thank you very much! As soon as updated, will try to do a new release.

HakanL commented 4 years ago

Sorry about that, but it's just the normal reformat that Visual Studio does to make it consistent (tab vs space).

HakanL commented 4 years ago

The source files have a mix of tab and space already. I don't know how I can easily undo the whitespace changes, VS reformats it automatically for me. In TortoiseGIT I can just turn on "ignore whitespace changes" to just see the code changes, could you try that?

jzabroski commented 4 years ago

I think BitBucket has an ignore whitespace feature, but I dont think GitHub does.

Good point on Visual Studio applying style changes. Should format the whole solution and check in a settings file so that people can hop into the project to reduce issues. Thougths?

HakanL commented 4 years ago

Yes, that would be very good to have it all re-formatted, at least in the files I was changing it was mixed up.

jzabroski commented 4 years ago

If I reformatted everything could you re-do the PR after that.

RickFrankel commented 4 years ago

Can this PR be merged please. This is a major bug for us using this library. We have no way around this particular issue that I can find at the moment.