malforge / mdk2

MIT License
77 stars 5 forks source link

intermediate-script.cs: error CS1038: #endregion directive expected #41

Open dosluke opened 2 months ago

dosluke commented 2 months ago

1>Writing intermediate script to C:\Users\me\source\repos\NewFancyFlightInfo\obj\intermediate-script.WhitespaceTrimmer.cs 1>Verifying that nothing went wrong 1>C:\Users\me\source\repos\NewFancyFlightInfo\obj\intermediate-script.cs(597,7): error CS1038: #endregion directive expected 1>Failed to compile the project.

i checked every cs file in the solution and they all close the in-game region directive with an endregion. I opened the intermediate script and this is what i found: first line: #region pre-script using System; using System.Linq;

a ways down:

`public class Program : MyGridProgram {

endregion

#region in-game

`

a ways down: ` }

#endregion
#region post-script

} class Skin`

no other region directives past that in the intermediate file.

my Program.cs file in which that last section of code came from DOES close the regions(the first endregion is from the in-game region above the code):

`}; }

    #endregion
    #region post-script
}

}

endregion`

dosluke commented 2 months ago

removing the region post-script and its associated endregion is a workaround, the script builds/deploys after that

malware-dev commented 2 months ago

Thanks. I think I see the problem immediately without opening the project. Region directives must be the only thing on the line.

malware-dev commented 2 months ago

Ok that's annoying. Me trying to reproduce this is a failure. MDK is correctly removing the regions for me.

dosluke commented 2 months ago

Wow that's odd.. I'll try to reproduce it today.

dosluke commented 2 months ago

image From intermediate

dosluke commented 2 months ago

image from program.cs

dosluke commented 2 months ago

looks like it has to do with cutting the class out of the namespace or something. im working on minimizing this solution to a bare minimum.

dosluke commented 2 months ago

image

dosluke commented 2 months ago

minimalbugexample.zip

dosluke commented 2 months ago

Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.11.4

sorry for comment spam. just attempting to give all needed info

malware-dev commented 2 months ago

Ah. Unusual use of region. Yes, that's likely to cause problems. I have to be honest, I don't know how much effort I'm willing to put in for this. It's counter to how MDK works with classes and might cause more problems than its worth. Maybe I can add something to detect when regions are used outside of classes, and prohibit it. Not in the analyzer package itself as people might be using that without the rest of MDK but the MDK executable itself could.

slammingprogramming commented 3 weeks ago

It sounds like this issue might stem from MDK’s handling of region directives, especially when they’re structured in ways that don’t align with typical class usage. While I understand that modifying MDK’s region-handling logic could be complex, perhaps a middle-ground solution could be to enhance the diagnostics. For example, MDK could provide a warning or alert when regions are used outside standard class structures or if regions aren’t on their own lines. This would let users know early on if their region setup might conflict with the minification process.

Alternatively, if MDK were to allow custom region-handling rules, users could toggle settings for “strict” region parsing (where regions must follow specific patterns) versus “flexible” parsing (where regions inside certain areas like namespaces are retained or adjusted to avoid compiler errors). This might make it easier for users who have unusual region structures to still use the minifier effectively.

I think adding a check directly in the MDK executable, as you suggested, could be a good compromise. It would give developers a heads-up before they run into errors while keeping MDK’s overall code structure and philosophy intact.

Thanks for considering these ideas—every improvement helps streamline the process for the community!