Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.cs.cshtml cannot become EmbeddedResource #3064

Closed
dsplaisted opened this issue Mar 7, 2018 · 12 comments · Fixed by #5824
Closed

File.cs.cshtml cannot become EmbeddedResource #3064

dsplaisted opened this issue Mar 7, 2018 · 12 comments · Fixed by #5824
Assignees
Labels
Milestone

Comments

@dsplaisted
Copy link
Member

From @davkean on March 5, 2018 22:43

From @abpiskunov on March 2, 2018 6:17

  1. Create a new core Web app
  2. in File Explorer find some cshtml page (Error.cshtml and rename it to Error.cs.cshtml.
  3. In VS change type of Error.cs.cshtml to EmbeddedResource (notice it will be removed from Content in csproj)
  4. Build
  5. Open assembly manifest and see - no embedded resources
  6. When rename file to Error.cshtml , build, assembly manifest does contain EmbeddedResource.

See this issue opened by customer originally : aspnet/Tooling#1066 (comment)

Copied from original issue: dotnet/project-system#3336

Copied from original issue: dotnet/sdk#2024

@dsplaisted dsplaisted self-assigned this Mar 7, 2018
@dsplaisted
Copy link
Member Author

From @davkean on March 5, 2018 22:43

This would be a build issue, no?

@dsplaisted
Copy link
Member Author

From @davkean on March 5, 2018 22:43

From @abpiskunov on March 2, 2018 16:51

Sounds like that or even could be sdk related, Content item type might somehow interfere with EmbeddedResource.

@dsplaisted
Copy link
Member Author

From @davkean on March 5, 2018 22:43

From @Pilchie on March 2, 2018 19:43

@livarcocc @nguerrera @dsplaisted ?

@dsplaisted
Copy link
Member Author

From @davkean on March 5, 2018 22:43

From @nguerrera on March 2, 2018 20:38

Could be sdk or msbuild. Feel free to move to sdk for next look.

@dsplaisted
Copy link
Member Author

From @davkean on March 5, 2018 22:43

From @dsplaisted on March 2, 2018 20:40

I want to take a look at this, but I suspect it is CPS not understanding how to modify the project to change the item type given the default globs that the project has.

@dsplaisted
Copy link
Member Author

From @davkean on March 5, 2018 22:43

From @abpiskunov on March 2, 2018 21:56

we have a vs feedback bug associated with that 574198. Who should i assign to? Who is doing first investigation here?

@dsplaisted
Copy link
Member Author

From @davkean on March 5, 2018 22:43

From @abpiskunov on March 5, 2018 20:7

Ok i am assigning the bug to Daniel first. Please route it further if it is not yours.

@dsplaisted
Copy link
Member Author

It turns out the issue here is that MSBuild (via the AssignCulture task) thinks that an EmbeddedResource with a name of Error.cs.cshtml is a Culture-specific resource for the cs culture. So ends up going in the satellite assembly for cs.

Related suggestion from @nguerrera: #1454 (comment)

Another approach would be to respect explicit WithCulture metadata as implying that no check is required.

This would let you explicitly turn this off if you don't want it.

@sandrock
Copy link

sandrock commented Sep 4, 2018

I have the same issue on my side. It looks like the one @rjamesnw posted. Some files get put into a satellite assembly because a part of the file name looks like a culture name.

I would like to the AssignCulture task to skip the file. The related issue #1454 is about forcing the task to assign a culture. I wish to do the opposite: preventing the task from executing.

Is there a workaround available?

@rainersigwald
Copy link
Member

I was optimistic about this but it didn't quite work

Incomplete workaround

  <Target Name="WorkaroundMSBuild3064" BeforeTargets="SplitResourcesByCulture">
    <!-- Workaround for https://github.com/Microsoft/msbuild/issues/3064 -->
    <ItemGroup>
      <_ResourcesWithCultureFilename Include="@(EmbeddedResource)" Condition="$([System.String]::Copy('%(Filename)').Contains('.cs'))" />

      <_MixedResourceWithNoCulture Include="@(_ResourcesWithCultureFilename)">
        <WithCulture>false</WithCulture>
      </_MixedResourceWithNoCulture>

      <EmbeddedResource Remove="@(_ResourcesWithCultureFilename)" />
    </ItemGroup>
  </Target>

It doesn't work because the CreateManifestResourceNames target calls CreateCSharpManifestResourceName which does its own independent rediscovery of culture, mangling it to, for example, ManifestResourceName = cs\3064.Views.Home.About.cshtml.

That could be avoided by explicitly specifying a ManifestResourceName, but I can't think of a good way to do the transform automatically--that's why it's done in a task in the first place.

A full solution would need to address the CreateCSharpManifestResourceName culture-discovery problem too.

@benvillalobos
Copy link
Member

benvillalobos commented Oct 14, 2020

Related feedback tickets (internal links):

Cannot embedded resource that contains “.ca.” (like something.ca.txt)

I found that when I try to embedded resource with “.ca.” in its name, build fails to do it.


Repro steps:

• Create some folder in project.

• Put there files ca.txt, .ca.txt, somethimg.ca.txt.

• Build project and verify embedded resources.

Embedded resource won't work for some filenames?

If I have an embedded resource file called “light.sms.txt”, then it is not embedded, but if I change it to “light.sms1.txt”, then it is embeded … emm … why?


Here’s what I do…



Create a new Vb.Net WinForm project

Add a text file called light.sms.txt and change build action to Embedded resource

Paste this code in Form1 …


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Static embededResources As String() = GetType(Form1). Assembly.GetManifestResourceNames()

MsgBox(embededResources.Length.ToString)

End Sub


Run the app - the result is 3

Change the embbeded filename to light.sms1.txt

Run the app - the result is now 4


Why doesn’t “light.sms.txt” get embedded?

@ahdung
Copy link

ahdung commented Oct 15, 2020

same issue, for me, the bad file name is Resources.en.xml or Resources.zh.xml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants