Self contained app does not include image files

ionut stoica 0 Reputation points
2023-06-26T10:35:08.76+00:00

I have a basic structure or a solution

+ MySolution
  + datasets
    ds1.model
    ds2.model
    template1.png
    template2.png
  + Project
     [REf] ProjectLib
  + ProjectLib
     [Link] datasets

Now, the ProjectLib.csproj has this

  <ItemGroup>
    <Content Include="$(ProjectDir)..\datasets\**" LinkBase="datasets">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Always</CopyToPublishDirectory>
      <ExcludeFromSingleFile>false</ExcludeFromSingleFile>
    </Content>
  </ItemGroup>

Now, the Project.csproj has this

    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishSingleFile>true</PublishSingleFile>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
    <SelfContained>true</SelfContained>
    <PublishReadyToRun>true</PublishReadyToRun>
    <SkipExtraFilesOnServer>false</SkipExtraFilesOnServer>
    <ExcludeApp_Data>false</ExcludeApp_Data>
    <DeleteExistingFiles>True</DeleteExistingFiles>

Checking with ILSpy - the Project.exe file contains the entire datasets folder, but without image files (the model files are included). The images just show up in the publish directory, but are not part of the single file.

If I add them to zip, then the zip will be properly bundled.

Is there any way to also include the images in the single file executable, just like the model files ?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,106 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,596 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,297 questions
{count} votes

2 answers

Sort by: Most helpful
  1. XuDong Peng-MSFT 11,256 Reputation points Microsoft Vendor
    2023-06-27T09:39:23.4766667+00:00

    Hi @ionut stoica,

    Need to publish your app with specific files? If this is the case, there is a CopyToPublishDirectory attribute for ItemGroup elements that determines whether to copy the file to the publish directory and can have one of the following values:

    • Always,
    • PreserveNewest
    • Never

    Something like:

    <ItemGroup>
      <None Include="template1.png" CopyToPublishDirectory="Always" />
    </ItemGroup>
    

    If possible, please try it and let me know the result, thank you. For more details, just refer to the doc: MSBuild reference for .NET SDK projects - CopyToPublishDirectory.

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.