fsprojects / FAKE

FAKE - F# Make
https://fake.build
Other
1.28k stars 582 forks source link

`System.IO.Stream` error when using SharpCompress #2702

Closed babysnakes closed 11 months ago

babysnakes commented 1 year ago

Description

When trying to use the SharpCompress library to create tar.gz archives (It seems that the functionality was removed in Fake 5) I used the following code:

module Archives =
    open SharpCompress.Archives
    open SharpCompress.Archives.Zip
    open SharpCompress.Common
    open SharpCompress.Writers
    open System.IO

    let compressZip dirName =
        let source = buildDir @@ dirName
        let zipFile = distDir @@ $"{dirName}.zip"
        Trace.log $"Creating ZIP archive: {zipFile}"
        using (ZipArchive.Create ()) (fun archive ->
            archive.AddAllFromDirectory(source)
            archive.SaveTo(zipFile, CompressionType.Deflate)
        )

    let compressTarGzip dirName =
        let source = buildDir @@ dirName
        let tarFile = distDir @@ $"{dirName}.tar.gz"
        Trace.log $"Creating TAR archive: {tarFile}"
        let writerOptions = WriterOptions(CompressionType.GZip)
        writerOptions.LeaveStreamOpen <- true
        using (File.OpenWrite(tarFile)) (fun stream ->
            using (WriterFactory.Open(stream, ArchiveType.GZip, writerOptions)) (fun writer ->
                writer.WriteAll(buildDir, "*", SearchOption.AllDirectories)
            )
        )

(The complete script is attached as TXT file).

When running dotnet fake build -t Publish I get the following error:

pwsh  dotnet fake build -t Publish
The last restore is still up to date. Nothing left to do.
Script is not valid:
        unknown (1,0)-(1,0): Error FS0193: The module/namespace 'System.IO' from compilation unit 'System.Runtime' did not contain the namespace, module or type 'SearchOption'
        C:\Users\haim\Code\Personal\roon-tagger\build.fsx (83,12)-(83,47): Error FS1109: A reference to the type 'System.IO.SearchOption' in assembly 'System.Runtime' was found, but the type could not be found in that assembly
        unknown (1,0)-(1,0): Error FS0193: The module/namespace 'System.IO' from compilation unit 'System.Runtime' did not contain the namespace, module or type 'Stream'
        C:\Users\haim\Code\Personal\roon-tagger\build.fsx (84,12)-(84,26): Error FS1109: A reference to the type 'System.IO.Stream' in assembly 'System.Runtime' was found, but the type could not be found in that assembly
        unknown (1,0)-(1,0): Error FS0193: The module/namespace 'System.IO' from compilation unit 'System.Runtime' did not contain the namespace, module or type 'Stream'
        C:\Users\haim\Code\Personal\roon-tagger\build.fsx (94,19)-(94,78): Error FS1109: A reference to the type 'System.IO.Stream' in assembly 'System.Runtime' was found, but the type could not be found in that assembly
        C:\Users\haim\Code\Personal\roon-tagger\build.fsx (95,16)-(95,31): Error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
Performance:
 - Cli parsing: 199 milliseconds
 - Packages: 54 milliseconds
 - Script compiling: 2 seconds
 - Runtime: 3 seconds

Repro steps

I guess running build script in an empty directory will generate the same error, but it could be copied to the top of the this repository to have the required files.

Expected behavior

To run correctly and compress the files 🙂.

Actual behavior

See errors above

Known workarounds

None that I know of.

Related information

Thanks in advance (and thank you for this great library).

github-actions[bot] commented 1 year ago

Welcome to the FAKE community! Thank you so much for creating your first issue and therefore improving the project!

babysnakes commented 1 year ago

I accidently pressed the submit button before filling out the bug. I'll update the description and notify when ready. Sorry.

babysnakes commented 1 year ago

Ok, now the description is ready.

yazeedobaid commented 1 year ago

Can you please re-try with the latest FAKE release?

babysnakes commented 1 year ago

Hi, thanks for the update. It might take me a few days. It seems that since the release of dotnet 7 together with the fact that I have global.json pointing at version 6 totally breaks fake and I'm getting all sort of errors. I'll try to fix them first and then I'll update regarding this issue.

babysnakes commented 1 year ago

Sadly I can not test it at this time. Since the release of dotnet 7 (with my project global.json forces version 6) fake is completely broken for me. As long as I don't change build.fsx.lock everything is ok, but once I delete it (regardless of which version of fake I'm using) I get all sorts of warnings and errors about incompatible versions or other errors if I try to force fsharp.core version. I'll gather the info and open a ticket regarding this. Once it's solved I'll be able to test this error.

Thanks

babysnakes commented 11 months ago

Hi,

I'm terribly sorry, I completely forgot about this issue. Only a couple of days ago I went to fix something and I was reminded about this issue 🙁.

I'm still having trouble running fake-cli with DotNet 6.0 so I converted the build.fsx to be a build project. Testing the SharpCompress library with FAKE 6 was a success and it seems to work without a problem so I'm closing the ticket.

Sorry again for the long delay ...