2

The idea is to have an application with a single file executable, despite the size, can be a very big file.

I'm using the "Single file deployment and executable" of .NET 6.0 with the following command:

publish {csproj.FullName} -c Release -r win-x64 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true --self-contained true -p:IncludeAllContentForSelfExtract=true -p:EnableCompressionInSingleFile=true

But when files are too big like greater then 4GB, I am not able to publish because of the following error:

C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018: System.ArgumentException: Stream length minus starting position is too large to hold a PEImage. (Parameter 'peStream') 
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018:    at System.Reflection.Internal.StreamExtensions.GetAndValidateSize(Stream stream, Int32 size, String streamParameterName) 
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(898,5): error MSB4018:    at System.Reflection.PortableExecutable.PEReader..ctor(Stream peStream, PEStreamOptions options, Int32 size) 

Any Idea how to fix it? Or another alternative to apply this idea.

João Antunes
  • 798
  • 8
  • 27
  • By any chance: Do u use a Fat32 Partition? – TheTanic Dec 14 '21 at 12:11
  • Why is your application so large? If you have large amounts of resources, is a single file application really the most suitable format? Consider for example updates. Requiring huge downloads each time may not be appreciated. Games for example often use some internal resource package format to facilitate easy patching. – JonasH Dec 14 '21 at 12:41
  • Q: [what is the maximum size of a PE file on 64-bit Windows?](https://stackoverflow.com/questions/6976693/what-is-the-maximum-size-of-a-pe-file-on-64-bit-windows) A: 4 GB. – Andrew Morton Dec 14 '21 at 13:16
  • @JonasH that is the requirement that I have :( We already make partial updates using web, but this is for offline installations. Probably I'll use a self extract approach using SFX Build. – João Antunes Dec 16 '21 at 12:18
  • I would think that if it is for "offline *installations*" you should provide an *installer*. Then single file deployment does not add much value, and using separate files may help by allowing the installer to skip updating files that have not changed. Single file deployment is more useful for small tools that is used without the need for installation. – JonasH Dec 20 '21 at 15:34

1 Answers1

0

After some research there is a limitation on C# that doesn't allow for a single file to be more than 4gb.

So the alternative that I've chosen is to use self-extracting zips.

The one that I've chosen is 7Zip. Using their SDK I am able to zip my files into a single file, and then create a self-extracting zip that has the .exe for the file execution and it works as expected!

João Antunes
  • 798
  • 8
  • 27