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

Changing .NET Core WPF project item from None to Resource does not embed item in output assembly #2240

Closed
rladuca opened this issue Nov 25, 2019 · 7 comments
Labels
area-System.Xaml External Non-WPF Issue External issue, not caused by WPF
Milestone

Comments

@rladuca
Copy link
Member

rladuca commented Nov 25, 2019

@vsfeedback commented on Sun Nov 24 2019

This issue has a corresponding ticket on Developer Community. Please vote and comment there to make sure your voice is heard.


This issue is present in VS2019 16.3.7, when targeting WPF and .NET Core 3.0 or .NET Framework 4.7.2 with the new SDK-Style .csproj format.

When changing [Build Action] for a file between [None] and [Resource] in SDK-Style .csproj, the Output dll/exe is not correctly recreated on Build (if there are no other changes triggering a recompile) - we have to do a Rebuild to get the desired effect!

NOTE: The Build command seems to do something, but the size of the resulting dll/exe does not reflect the removal/addition of the built-in resource content. After a Rebuild (or after changing code etc and doing another Build) the size of the dll/exe is corrected.

Interestingly enough, the same issue does not seem to apply when switching between [None] and [EmbeddedResource].

The issue can easily be reproduced:

  • Create a new WPF application (with SDK-style .csproj file).
  • Drop an image file or similar with a size that's large compared to the application .dll/.exe output (just to easily spot the size difference when the image is embedded or not).
  • Initially the image file will have [Build Action = None]. Build the app and note the size of the output dll/exe.
  • Then change to [Build Action = Resource] and Build again (not Rebuild, and no code change in between).
  • The build seems to update the dll/exe, but the output size does not change.
  • Now, do a Rebuild (or change a source-code file and Build). The output size will change.

The above steps can be used to repeatedly reproduce the (wrong size) issue by toggling between [None] and [Resource] - doing a build does not change the size, but doing a Rebuild correctly updates the size (of the output dll/exe).


Original Comments

Visual Studio Feedback System on 11/1/2019, 04:48 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Sara Liu [MSFT] on 11/4/2019, 06:17 PM:

Thank you for your feedback, this issue has been escalated for further investigation and if there is any process, I will inform you immediately.


Original Solutions

(no solutions)


@drewnoakes commented on Sun Nov 24 2019

I intend to transfer this to https://github.com/dotnet/wpf but no longer have permission to do so. However this may be related to a GitHub outage seen today, so will try again later before escalating.


@sharwell commented on Sun Nov 24 2019

@terrajobst can you transfer this issue for us?

@drewnoakes
Copy link
Member

@rladuca would you please move the Developer Community ticket to the appropriate WPF area path?

@arpitmathur
Copy link
Contributor

@rainersigwald Have you seen something like this before? Does this look like an msbuild issue?

@rainersigwald
Copy link
Member

@benvillalobos, can you take a look at this repro and see where things are going wrong?

@rladuca
Copy link
Member Author

rladuca commented Dec 19, 2019

@benvillalobos Did you ever get to look into this?

@benvillalobos
Copy link
Member

@rladuca Not yet unfortunately. I'm currently focused on a high priority bug, but this is still on my to-do list.

@soul4soul
Copy link

Still appears to be a bug doing a rebuild fixed my problem. Possibly related, changing the image build type from None to Resource added 2 itemgroups to the csproj file. One to remove the image and one to include it. I manually removed the itemgroup for removing the resource. Then I performed a rebuild and things started to work.

  <ItemGroup>
    <Resource Remove="Images\info.png" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Mono.Options" Version="6.6.0.161" />
  </ItemGroup>

  <ItemGroup>
    <Resource Include="Images\info.png" />
  </ItemGroup>

@verelpode
Copy link

WPF is a red herring because this problem also affects non-WPF projects that target SDK/NETFW/5, such as non-WPF Console projects for ASP.NET 5, or a Windows Service, or stuff for MS Azure.
"Build Action" = "Resource" is not only for WPF projects. Any app, including non-WPF Console programs, can use System.Resources.ResourceManager (alternatively System.Resources.ResourceReader) to read these resources at runtime.

I've written detailed notes about this in the later message in dotnet/project-system#4534 (comment)

@ryalanms ryalanms added the External Non-WPF Issue External issue, not caused by WPF label Aug 27, 2021
@ryalanms ryalanms added this to the Future milestone Aug 27, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Apr 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Xaml External Non-WPF Issue External issue, not caused by WPF
Projects
None yet
Development

No branches or pull requests

8 participants