@@ -132,7 +132,7 @@ public bool SyncIfNeeded(IEnumerable<string> affectedFiles, IEnumerable<string>
132132
133133 SyncProject ( assembly ,
134134 allAssetProjectParts ,
135- responseFilesData : ParseResponseFileData ( assembly ) . ToArray ( ) ) ;
135+ ParseResponseFileData ( assembly ) ) ;
136136 }
137137
138138 return true ;
@@ -283,11 +283,11 @@ public void GenerateAndWriteSolutionAndProjects()
283283 {
284284 SyncProject ( assembly ,
285285 allAssetProjectParts ,
286- responseFilesData : ParseResponseFileData ( assembly ) . ToArray ( ) ) ;
286+ ParseResponseFileData ( assembly ) ) ;
287287 }
288288 }
289289
290- private IEnumerable < ResponseFileData > ParseResponseFileData ( Assembly assembly )
290+ private ResponseFileData [ ] ParseResponseFileData ( Assembly assembly )
291291 {
292292 var systemReferenceDirectories = CompilationPipeline . GetSystemAssemblyDirectories ( assembly . compilerOptions . ApiCompatibilityLevel ) ;
293293
@@ -309,7 +309,7 @@ private IEnumerable<ResponseFileData> ParseResponseFileData(Assembly assembly)
309309 }
310310 }
311311
312- return responseFilesData . Select ( x => x . Value ) ;
312+ return responseFilesData . Select ( x => x . Value ) . ToArray ( ) ;
313313 }
314314
315315 private Dictionary < string , string > GenerateAllAssetProjectParts ( )
@@ -383,11 +383,11 @@ internal virtual void IncludeAsset(StringBuilder builder, IncludeAssetTag tag, s
383383 private void SyncProject (
384384 Assembly assembly ,
385385 Dictionary < string , string > allAssetsProjectParts ,
386- ResponseFileData [ ] responseFilesData )
386+ ResponseFileData [ ] responseFileData )
387387 {
388388 SyncProjectFileIfNotChanged (
389389 ProjectFile ( assembly ) ,
390- ProjectText ( assembly , allAssetsProjectParts , responseFilesData ) ) ;
390+ ProjectText ( assembly , allAssetsProjectParts , responseFileData ) ) ;
391391 }
392392
393393 private void SyncProjectFileIfNotChanged ( string path , string newContents )
@@ -476,9 +476,9 @@ private void SyncFileIfNotChanged(string filename, string newContents)
476476
477477 private string ProjectText ( Assembly assembly ,
478478 Dictionary < string , string > allAssetsProjectParts ,
479- ResponseFileData [ ] responseFilesData )
479+ ResponseFileData [ ] responseFileData )
480480 {
481- ProjectHeader ( assembly , responseFilesData , out StringBuilder projectBuilder ) ;
481+ ProjectHeader ( assembly , responseFileData , out StringBuilder projectBuilder ) ;
482482
483483 var references = new List < string > ( ) ;
484484
@@ -513,7 +513,7 @@ private string ProjectText(Assembly assembly,
513513
514514 projectBuilder . Append ( @" <ItemGroup>" ) . Append ( k_WindowsNewline ) ;
515515
516- var responseRefs = responseFilesData . SelectMany ( x => x . FullPathReferences . Select ( r => r ) ) ;
516+ var responseRefs = responseFileData . SelectMany ( x => x . FullPathReferences . Select ( r => r ) ) ;
517517 var internalAssemblyReferences = assembly . assemblyReferences
518518 . Where ( i => ! i . sourceFiles . Any ( ShouldFileBePartOfSolution ) ) . Select ( i => i . outputPath ) ;
519519 var allReferences =
@@ -595,8 +595,12 @@ internal virtual string SolutionFileImpl()
595595 return Path . Combine ( ProjectDirectory . NormalizePathSeparators ( ) , $ "{ InvalidCharactersRegexPattern . Replace ( m_ProjectName , "_" ) } .sln") ;
596596 }
597597
598- internal string GetLangVersion ( Assembly assembly )
598+ internal string GetLangVersion ( Assembly assembly , ResponseFileData [ ] responseFileData )
599599 {
600+ var langVersion = GetOtherArguments ( responseFileData , "langversion" ) . FirstOrDefault ( ) ;
601+ if ( ! string . IsNullOrEmpty ( langVersion ) )
602+ return langVersion ;
603+
600604 var targetLanguageVersion = "latest" ; // danger: latest is not the same absolute value depending on the VS version.
601605 if ( m_CurrentInstallation != null )
602606 {
@@ -610,9 +614,9 @@ internal string GetLangVersion(Assembly assembly)
610614 return targetLanguageVersion ;
611615 }
612616
613- private static IEnumerable < string > GetOtherArguments ( ResponseFileData [ ] responseFilesData , HashSet < string > names )
617+ private static IEnumerable < string > GetOtherArguments ( ResponseFileData [ ] responseFileData , string name )
614618 {
615- var lines = responseFilesData
619+ var lines = responseFileData
616620 . SelectMany ( x => x . OtherArguments )
617621 . Where ( l => ! string . IsNullOrEmpty ( l ) )
618622 . Select ( l => l . Trim ( ) )
@@ -628,7 +632,7 @@ private static IEnumerable<string> GetOtherArguments(ResponseFileData[] response
628632 . Substring ( 1 , index - 1 )
629633 . Trim ( ) ;
630634
631- if ( ! names . Contains ( key ) )
635+ if ( name != key )
632636 continue ;
633637
634638 if ( argument . Length <= index )
@@ -640,7 +644,7 @@ private static IEnumerable<string> GetOtherArguments(ResponseFileData[] response
640644 }
641645 }
642646
643- private void SetAnalyzerAndSourceGeneratorProperties ( Assembly assembly , ResponseFileData [ ] responseFilesData , ProjectProperties properties )
647+ private void SetAnalyzerAndSourceGeneratorProperties ( Assembly assembly , ResponseFileData [ ] responseFileData , ProjectProperties properties )
644648 {
645649 if ( m_CurrentInstallation == null || ! m_CurrentInstallation . SupportsAnalyzers )
646650 return ;
@@ -672,8 +676,9 @@ private void SetAnalyzerAndSourceGeneratorProperties(Assembly assembly, Response
672676#endif
673677
674678 // Analyzers and additional files provided by csc.rsp
675- analyzers . AddRange ( GetOtherArguments ( responseFilesData , new HashSet < string > ( new [ ] { "analyzer" , "a" } ) ) ) ;
676- additionalFilePaths . AddRange ( GetOtherArguments ( responseFilesData , new HashSet < string > ( new [ ] { "additionalfile" } ) ) ) ;
679+ analyzers . AddRange ( GetOtherArguments ( responseFileData , "analyzer" ) ) ;
680+ analyzers . AddRange ( GetOtherArguments ( responseFileData , "a" ) ) ;
681+ additionalFilePaths . AddRange ( GetOtherArguments ( responseFileData , "additionalfile" ) ) ;
677682
678683 properties . RulesetPath = ToNormalizedPath ( rulesetPath ) ;
679684 properties . Analyzers = ToNormalizedPaths ( analyzers ) ;
@@ -699,7 +704,7 @@ private string[] ToNormalizedPaths(IEnumerable<string> values)
699704
700705 private void ProjectHeader (
701706 Assembly assembly ,
702- ResponseFileData [ ] responseFilesData ,
707+ ResponseFileData [ ] responseFileData ,
703708 out StringBuilder headerBuilder
704709 )
705710 {
@@ -708,21 +713,21 @@ out StringBuilder headerBuilder
708713 var projectProperties = new ProjectProperties
709714 {
710715 ProjectGuid = ProjectGuid ( assembly ) ,
711- LangVersion = GetLangVersion ( assembly ) ,
716+ LangVersion = GetLangVersion ( assembly , responseFileData ) ,
712717 AssemblyName = assembly . name ,
713718 RootNamespace = GetRootNamespace ( assembly ) ,
714719 OutputPath = assembly . outputPath ,
715720 // RSP alterable
716- Defines = assembly . defines . Concat ( responseFilesData . SelectMany ( x => x . Defines ) ) . Distinct ( ) . ToArray ( ) ,
717- Unsafe = assembly . compilerOptions . AllowUnsafeCode | responseFilesData . Any ( x => x . Unsafe ) ,
721+ Defines = assembly . defines . Concat ( responseFileData . SelectMany ( x => x . Defines ) ) . Distinct ( ) . ToArray ( ) ,
722+ Unsafe = assembly . compilerOptions . AllowUnsafeCode | responseFileData . Any ( x => x . Unsafe ) ,
718723 // VSTU Flavoring
719724 FlavoringProjectType = projectType + ":" + ( int ) projectType ,
720725 FlavoringBuildTarget = EditorUserBuildSettings . activeBuildTarget + ":" + ( int ) EditorUserBuildSettings . activeBuildTarget ,
721726 FlavoringUnityVersion = Application . unityVersion ,
722727 FlavoringPackageVersion = VisualStudioIntegration . PackageVersion ( ) ,
723728 } ;
724729
725- SetAnalyzerAndSourceGeneratorProperties ( assembly , responseFilesData , projectProperties ) ;
730+ SetAnalyzerAndSourceGeneratorProperties ( assembly , responseFileData , projectProperties ) ;
726731
727732 GetProjectHeader ( projectProperties , out headerBuilder ) ;
728733 }
0 commit comments