| 
56 | 56 |  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>  | 
57 | 57 |  * @author <a href="mailto:matthew.pocock@ncl.ac.uk">Matthew Pocock</a>  | 
58 | 58 |  * @author <a href="mailto:chris.stevenson@gmail.com">Chris Stevenson</a>  | 
 | 59 | + * @author <a href="mailto:mazas.marc@gmail.com">Marc Mazas</a>  | 
59 | 60 |  */  | 
60 | 61 | @Named("csharp")  | 
61 | 62 | public class CSharpCompiler extends AbstractCompiler {  | 
@@ -219,6 +220,171 @@ private String findExecutable(CompilerConfiguration config) {  | 
219 | 220 |     Options can be of the form -option or /option  | 
220 | 221 |         */  | 
221 | 222 | 
 
  | 
 | 223 | +    /*  | 
 | 224 | +    C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\Roslyn>csc -help -preferreduilang:en  | 
 | 225 | +    Microsoft (R) Visual C# Compiler version 4.11.0-3.24460.3 (5649376e)  | 
 | 226 | +    Copyright (C) Microsoft Corporation. All rights reserved.  | 
 | 227 | +
  | 
 | 228 | +
  | 
 | 229 | +                                 Visual C# Compiler Options  | 
 | 230 | +
  | 
 | 231 | +                           - OUTPUT FILES -  | 
 | 232 | +    -out:<file>                   Specify output file name (default: base name of  | 
 | 233 | +                                  file with main class or first file)  | 
 | 234 | +    -target:exe                   Build a console executable (default) (Short  | 
 | 235 | +                                  form: -t:exe)  | 
 | 236 | +    -target:winexe                Build a Windows executable (Short form:  | 
 | 237 | +                                  -t:winexe)  | 
 | 238 | +    -target:library               Build a library (Short form: -t:library)  | 
 | 239 | +    -target:module                Build a module that can be added to another  | 
 | 240 | +                                  assembly (Short form: -t:module)  | 
 | 241 | +    -target:appcontainerexe       Build an Appcontainer executable (Short form:  | 
 | 242 | +                                  -t:appcontainerexe)  | 
 | 243 | +    -target:winmdobj              Build a Windows Runtime intermediate file that  | 
 | 244 | +                                  is consumed by WinMDExp (Short form: -t:winmdobj)  | 
 | 245 | +    -doc:<file>                   XML Documentation file to generate  | 
 | 246 | +    -refout:<file>                Reference assembly output to generate  | 
 | 247 | +    -platform:<string>            Limit which platforms this code can run on: x86,  | 
 | 248 | +                                  Itanium, x64, arm, arm64, anycpu32bitpreferred, or  | 
 | 249 | +                                  anycpu. The default is anycpu.  | 
 | 250 | +
  | 
 | 251 | +                           - INPUT FILES -  | 
 | 252 | +    -recurse:<wildcard>           Include all files in the current directory and  | 
 | 253 | +                                  subdirectories according to the wildcard  | 
 | 254 | +                                  specifications  | 
 | 255 | +    -reference:<alias>=<file>     Reference metadata from the specified assembly  | 
 | 256 | +                                  file using the given alias (Short form: -r)  | 
 | 257 | +    -reference:<file list>        Reference metadata from the specified assembly  | 
 | 258 | +                                  files (Short form: -r)  | 
 | 259 | +    -addmodule:<file list>        Link the specified modules into this assembly  | 
 | 260 | +    -link:<file list>             Embed metadata from the specified interop  | 
 | 261 | +                                  assembly files (Short form: -l)  | 
 | 262 | +    -analyzer:<file list>         Run the analyzers from this assembly  | 
 | 263 | +                                  (Short form: -a)  | 
 | 264 | +    -additionalfile:<file list>   Additional files that don't directly affect code  | 
 | 265 | +                                  generation but may be used by analyzers for producing  | 
 | 266 | +                                  errors or warnings.  | 
 | 267 | +    -embed                        Embed all source files in the PDB.  | 
 | 268 | +    -embed:<file list>            Embed specific files in the PDB.  | 
 | 269 | +
  | 
 | 270 | +                           - RESOURCES -  | 
 | 271 | +    -win32res:<file>              Specify a Win32 resource file (.res)  | 
 | 272 | +    -win32icon:<file>             Use this icon for the output  | 
 | 273 | +    -win32manifest:<file>         Specify a Win32 manifest file (.xml)  | 
 | 274 | +    -nowin32manifest              Do not include the default Win32 manifest  | 
 | 275 | +    -resource:<resinfo>           Embed the specified resource (Short form: -res)  | 
 | 276 | +    -linkresource:<resinfo>       Link the specified resource to this assembly  | 
 | 277 | +                                  (Short form: -linkres) Where the resinfo format  | 
 | 278 | +                                  is <file>[,<string name>[,public|private]]  | 
 | 279 | +
  | 
 | 280 | +                           - CODE GENERATION -  | 
 | 281 | +    -debug[+|-]                   Emit debugging information  | 
 | 282 | +    -debug:{full|pdbonly|portable|embedded}  | 
 | 283 | +                                  Specify debugging type ('full' is default,  | 
 | 284 | +                                  'portable' is a cross-platform format,  | 
 | 285 | +                                  'embedded' is a cross-platform format embedded into  | 
 | 286 | +                                  the target .dll or .exe)  | 
 | 287 | +    -optimize[+|-]                Enable optimizations (Short form: -o)  | 
 | 288 | +    -deterministic                Produce a deterministic assembly  | 
 | 289 | +                                  (including module version GUID and timestamp)  | 
 | 290 | +    -refonly                      Produce a reference assembly in place of the main output  | 
 | 291 | +    -instrument:TestCoverage      Produce an assembly instrumented to collect  | 
 | 292 | +                                  coverage information  | 
 | 293 | +    -sourcelink:<file>            Source link info to embed into PDB.  | 
 | 294 | +
  | 
 | 295 | +                           - ERRORS AND WARNINGS -  | 
 | 296 | +    -warnaserror[+|-]             Report all warnings as errors  | 
 | 297 | +    -warnaserror[+|-]:<warn list> Report specific warnings as errors  | 
 | 298 | +                                  (use "nullable" for all nullability warnings)  | 
 | 299 | +    -warn:<n>                     Set warning level (0 or higher) (Short form: -w)  | 
 | 300 | +    -nowarn:<warn list>           Disable specific warning messages  | 
 | 301 | +                                  (use "nullable" for all nullability warnings)  | 
 | 302 | +    -ruleset:<file>               Specify a ruleset file that disables specific  | 
 | 303 | +                                  diagnostics.  | 
 | 304 | +    -errorlog:<file>[,version=<sarif_version>]  | 
 | 305 | +                                  Specify a file to log all compiler and analyzer  | 
 | 306 | +                                  diagnostics.  | 
 | 307 | +                                  sarif_version:{1|2|2.1} Default is 1. 2 and 2.1  | 
 | 308 | +                                  both mean SARIF version 2.1.0.  | 
 | 309 | +    -reportanalyzer               Report additional analyzer information, such as  | 
 | 310 | +                                  execution time.  | 
 | 311 | +    -skipanalyzers[+|-]           Skip execution of diagnostic analyzers.  | 
 | 312 | +
  | 
 | 313 | +                           - LANGUAGE -  | 
 | 314 | +    -checked[+|-]                 Generate overflow checks  | 
 | 315 | +    -unsafe[+|-]                  Allow 'unsafe' code  | 
 | 316 | +    -define:<symbol list>         Define conditional compilation symbol(s) (Short  | 
 | 317 | +                                  form: -d)  | 
 | 318 | +    -langversion:?                Display the allowed values for language version  | 
 | 319 | +    -langversion:<string>         Specify language version such as  | 
 | 320 | +                                  `latest` (latest version, including minor versions),  | 
 | 321 | +                                  `default` (same as `latest`),  | 
 | 322 | +                                  `latestmajor` (latest version, excluding minor versions),  | 
 | 323 | +                                  `preview` (latest version, including features in unsupported preview),  | 
 | 324 | +                                  or specific versions like `6` or `7.1`  | 
 | 325 | +    -nullable[+|-]                Specify nullable context option enable|disable.  | 
 | 326 | +    -nullable:{enable|disable|warnings|annotations}  | 
 | 327 | +                                  Specify nullable context option enable|disable|warnings|annotations.  | 
 | 328 | +
  | 
 | 329 | +                           - SECURITY -  | 
 | 330 | +    -delaysign[+|-]               Delay-sign the assembly using only the public  | 
 | 331 | +                                  portion of the strong name key  | 
 | 332 | +    -publicsign[+|-]              Public-sign the assembly using only the public  | 
 | 333 | +                                  portion of the strong name key  | 
 | 334 | +    -keyfile:<file>               Specify a strong name key file  | 
 | 335 | +    -keycontainer:<string>        Specify a strong name key container  | 
 | 336 | +    -highentropyva[+|-]           Enable high-entropy ASLR  | 
 | 337 | +
  | 
 | 338 | +                           - MISCELLANEOUS -  | 
 | 339 | +    @<file>                       Read response file for more options  | 
 | 340 | +    -help                         Display this usage message (Short form: -?)  | 
 | 341 | +    -nologo                       Suppress compiler copyright message  | 
 | 342 | +    -noconfig                     Do not auto include CSC.RSP file  | 
 | 343 | +    -parallel[+|-]                Concurrent build.  | 
 | 344 | +    -version                      Display the compiler version number and exit.  | 
 | 345 | +
  | 
 | 346 | +                           - ADVANCED -  | 
 | 347 | +    -baseaddress:<address>        Base address for the library to be built  | 
 | 348 | +    -checksumalgorithm:<alg>      Specify algorithm for calculating source file  | 
 | 349 | +                                  checksum stored in PDB. Supported values are:  | 
 | 350 | +                                  SHA1 or SHA256 (default).  | 
 | 351 | +    -codepage:<n>                 Specify the codepage to use when opening source  | 
 | 352 | +                                  files  | 
 | 353 | +    -utf8output                   Output compiler messages in UTF-8 encoding  | 
 | 354 | +    -main:<type>                  Specify the type that contains the entry point  | 
 | 355 | +                                  (ignore all other possible entry points) (Short  | 
 | 356 | +                                  form: -m)  | 
 | 357 | +    -fullpaths                    Compiler generates fully qualified paths  | 
 | 358 | +    -filealign:<n>                Specify the alignment used for output file  | 
 | 359 | +                                  sections  | 
 | 360 | +    -pathmap:<K1>=<V1>,<K2>=<V2>,...  | 
 | 361 | +                                  Specify a mapping for source path names output by  | 
 | 362 | +                                  the compiler.  | 
 | 363 | +    -pdb:<file>                   Specify debug information file name (default:  | 
 | 364 | +                                  output file name with .pdb extension)  | 
 | 365 | +    -errorendlocation             Output line and column of the end location of  | 
 | 366 | +                                  each error  | 
 | 367 | +    -preferreduilang              Specify the preferred output language name.  | 
 | 368 | +    -nosdkpath                    Disable searching the default SDK path for standard library assemblies.  | 
 | 369 | +    -nostdlib[+|-]                Do not reference standard library (mscorlib.dll)  | 
 | 370 | +    -subsystemversion:<string>    Specify subsystem version of this assembly  | 
 | 371 | +    -lib:<file list>              Specify additional directories to search in for  | 
 | 372 | +                                  references  | 
 | 373 | +    -errorreport:<string>         Specify how to handle internal compiler errors:  | 
 | 374 | +                                  prompt, send, queue, or none. The default is  | 
 | 375 | +                                  queue.  | 
 | 376 | +    -appconfig:<file>             Specify an application configuration file  | 
 | 377 | +                                  containing assembly binding settings  | 
 | 378 | +    -moduleassemblyname:<string>  Name of the assembly which this module will be  | 
 | 379 | +                                  a part of  | 
 | 380 | +    -modulename:<string>          Specify the name of the source module  | 
 | 381 | +    -generatedfilesout:<dir>      Place files generated during compilation in the  | 
 | 382 | +                                  specified directory.  | 
 | 383 | +    -reportivts[+|-]                    Output information on all IVTs granted to this  | 
 | 384 | +                                  assembly by all dependencies, and annotate foreign assembly  | 
 | 385 | +                                  accessibility errors with what assembly they came from.  | 
 | 386 | +     */  | 
 | 387 | + | 
222 | 388 |     private String[] buildCompilerArguments(CompilerConfiguration config, String[] sourceFiles)  | 
223 | 389 |             throws CompilerException {  | 
224 | 390 |         List<String> args = new ArrayList<>();  | 
@@ -291,7 +457,7 @@ private String[] buildCompilerArguments(CompilerConfiguration config, String[] s  | 
291 | 457 |         }  | 
292 | 458 | 
 
  | 
293 | 459 |         // ----------------------------------------------------------------------  | 
294 |  | -        // Xml Doc output  | 
 | 460 | +        // Nowarn option  | 
295 | 461 |         // ----------------------------------------------------------------------  | 
296 | 462 | 
 
  | 
297 | 463 |         String nowarn = compilerArguments.get("-nowarn");  | 
@@ -343,6 +509,33 @@ private String[] buildCompilerArguments(CompilerConfiguration config, String[] s  | 
343 | 509 |             args.add("/nologo");  | 
344 | 510 |         }  | 
345 | 511 | 
 
  | 
 | 512 | +        // ----------------------------------------------------------------------  | 
 | 513 | +        // Unsafe option  | 
 | 514 | +        // ----------------------------------------------------------------------  | 
 | 515 | +        String unsafe = compilerArguments.get("-unsafe");  | 
 | 516 | + | 
 | 517 | +        if (!StringUtils.isEmpty(unsafe) && unsafe.equals("true")) {  | 
 | 518 | +            args.add("/unsafe");  | 
 | 519 | +        }  | 
 | 520 | + | 
 | 521 | +        // ----------------------------------------------------------------------  | 
 | 522 | +        // PreferredUILang option  | 
 | 523 | +        // ----------------------------------------------------------------------  | 
 | 524 | +        String preferreduilang = compilerArguments.get("-preferreduilang");  | 
 | 525 | + | 
 | 526 | +        if (!StringUtils.isEmpty(preferreduilang)) {  | 
 | 527 | +            args.add("/preferreduilang:" + preferreduilang);  | 
 | 528 | +        }  | 
 | 529 | + | 
 | 530 | +        // ----------------------------------------------------------------------  | 
 | 531 | +        // Utf8Output option  | 
 | 532 | +        // ----------------------------------------------------------------------  | 
 | 533 | +        String utf8output = compilerArguments.get("-utf8output");  | 
 | 534 | + | 
 | 535 | +        if (!StringUtils.isEmpty(utf8output)) {  | 
 | 536 | +            args.add("/utf8output:");  | 
 | 537 | +        }  | 
 | 538 | + | 
346 | 539 |         // ----------------------------------------------------------------------  | 
347 | 540 |         // add any resource files  | 
348 | 541 |         // ----------------------------------------------------------------------  | 
 | 
0 commit comments