Esempio n. 1
0
        private string GenerateRoslynAnalyzerRulesetPath(ProjectPart assembly, ILookup <string, string> otherResponseFilesData)
        {
#if UNITY_2020_2_OR_NEWER
            return(GenerateAnalyserRuleSet(otherResponseFilesData["ruleset"].Append(assembly.CompilerOptions.RoslynAnalyzerRulesetPath).Where(a => !string.IsNullOrEmpty(a)).Distinct().Select(x => MakeAbsolutePath(x).NormalizePath()).ToArray()));
#else
            return(GenerateAnalyserRuleSet(otherResponseFilesData["ruleset"].Distinct().Select(x => MakeAbsolutePath(x).NormalizePath()).ToArray()));
#endif
        }
Esempio n. 2
0
 private void SyncProject(
     ProjectPart island,
     Type[] types)
 {
     SyncProjectFileIfNotChanged(
         ProjectFile(island),
         ProjectText(island),
         types);
 }
 private void SyncProject(
     ProjectPart island,
     Type[] types,
     string[] roslynAnalyzerDllPaths)
 {
     SyncProjectFileIfNotChanged(
         ProjectFile(island),
         ProjectText(island, roslynAnalyzerDllPaths),
         types);
 }
        private string ProjectHeader(
            ProjectPart assembly,
            List <ResponseFileData> responseFilesData,
            string[] roslynAnalyzerDllPaths
            )
        {
            var otherResponseFilesData = GetOtherArgumentsFromResponseFilesData(responseFilesData);
            var arguments = new object[]
            {
                k_ToolsVersion,
                k_ProductVersion,
                ProjectGuid(assembly.Name, assembly.OutputPath),
                InternalEditorUtility.GetEngineAssemblyPath(),
                InternalEditorUtility.GetEditorAssemblyPath(),
                string.Join(";", assembly.Defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
                MSBuildNamespaceUri,
                assembly.Name,
                assembly.OutputPath,
                assembly.RootNamespace,
                k_TargetFrameworkVersion,
                GenerateLangVersion(otherResponseFilesData["langversion"], assembly),
                k_BaseDirectory,
                assembly.CompilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
                GenerateNoWarn(otherResponseFilesData["nowarn"].Distinct().ToArray()),
                GenerateAnalyserItemGroup(
                    otherResponseFilesData["analyzer"].Concat(otherResponseFilesData["a"])
                    .SelectMany(x => x.Split(';'))
                    .Concat(roslynAnalyzerDllPaths)
                    .Distinct()
                    .ToArray()),
                GenerateAnalyserAdditionalFiles(otherResponseFilesData["additionalfile"].SelectMany(x => x.Split(';')).Distinct().ToArray()),
        #if UNITY_2020_2_OR_NEWER
                GenerateAnalyserRuleSet(otherResponseFilesData["ruleset"].Append(assembly.CompilerOptions.RoslynAnalyzerRulesetPath).Where(a => !string.IsNullOrEmpty(a)).Distinct().ToArray()),
        #else
                GenerateAnalyserRuleSet(otherResponseFilesData["ruleset"].Distinct().ToArray()),
        #endif
                GenerateWarningLevel(otherResponseFilesData["warn"].Concat(otherResponseFilesData["w"]).Distinct()),
                GenerateWarningAsError(otherResponseFilesData["warnaserror"]),
                GenerateDocumentationFile(otherResponseFilesData["doc"].ToArray()),
                GenerateNullable(otherResponseFilesData["nullable"])
            };

            try
            {
                return(string.Format(GetProjectHeaderTemplate(), arguments));
            }
            catch (Exception)
            {
                throw new NotSupportedException(
                          "Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " +
                          arguments.Length);
            }
        }
        private string GenerateLangVersion(IEnumerable <string> langVersionList, ProjectPart assembly)
        {
            var langVersion = langVersionList.FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(langVersion))
            {
                return(langVersion);
            }
#if UNITY_2020_2_OR_NEWER
            return(assembly.CompilerOptions.LanguageVersion);
#endif
            return(k_TargetLanguageVersion);
        }
        private string ProjectText(ProjectPart assembly,
                                   string[] roslynAnalyzerDllPaths)
        {
            var responseFilesData = assembly.ParseResponseFileData(m_AssemblyNameProvider, ProjectDirectory).ToList();
            var projectBuilder    = new StringBuilder(ProjectHeader(assembly, responseFilesData, roslynAnalyzerDllPaths));

            foreach (var file in assembly.SourceFiles)
            {
                var fullFile = EscapedRelativePathFor(file);
                projectBuilder.Append("     <Compile Include=\"").Append(fullFile).Append("\" />").Append(Environment.NewLine);
            }

            projectBuilder.Append(assembly.AssetsProjectPart);

            var responseRefs = responseFilesData.SelectMany(x => x.FullPathReferences.Select(r => r));
            var internalAssemblyReferences = assembly.AssemblyReferences
                                             .Where(reference => !reference.sourceFiles.Any(ShouldFileBePartOfSolution)).Select(i => i.outputPath);
            var allReferences =
                assembly.CompiledAssemblyReferences
                .Union(responseRefs)
                .Union(internalAssemblyReferences).ToArray();

            foreach (var reference in allReferences)
            {
                var fullReference = Path.IsPathRooted(reference) ? reference : Path.Combine(ProjectDirectory, reference);
                AppendReference(fullReference, projectBuilder);
            }

            if (0 < assembly.AssemblyReferences.Length)
            {
                projectBuilder.Append("  </ItemGroup>").Append(Environment.NewLine);
                projectBuilder.Append("  <ItemGroup>").Append(Environment.NewLine);
                foreach (var reference in assembly.AssemblyReferences.Where(i => i.sourceFiles.Any(ShouldFileBePartOfSolution)))
                {
                    projectBuilder.Append("    <ProjectReference Include=\"").Append(reference.name).Append(GetProjectExtension()).Append("\">").Append(Environment.NewLine);
                    projectBuilder.Append("      <Project>{").Append(ProjectGuid(reference.name, reference.outputPath)).Append("}</Project>").Append(Environment.NewLine);
                    projectBuilder.Append("      <Name>").Append(reference.name).Append("</Name>").Append(Environment.NewLine);
                    projectBuilder.Append("    </ProjectReference>").Append(Environment.NewLine);
                }
            }

            projectBuilder.Append(ProjectFooter());
            return(projectBuilder.ToString());
        }
Esempio n. 7
0
        private string ProjectHeader(
            ProjectPart assembly,
            List <ResponseFileData> responseFilesData
            )
        {
            var otherResponseFilesData = GetOtherArgumentsFromResponseFilesData(responseFilesData);
            var arguments = new object[]
            {
                k_ToolsVersion,
                k_ProductVersion,
                ProjectGuid(m_AssemblyNameProvider.GetProjectName(assembly.Name, assembly.Defines)),
                InternalEditorUtility.GetEngineAssemblyPath(),
                InternalEditorUtility.GetEditorAssemblyPath(),
                string.Join(";", assembly.Defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
                MSBuildNamespaceUri,
                assembly.Name,
                assembly.OutputPath,
                assembly.RootNamespace,
                assembly.CompilerOptions.ApiCompatibilityLevel,
                GenerateLangVersion(otherResponseFilesData["langversion"], assembly),
                k_BaseDirectory,
                assembly.CompilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
                GenerateNoWarn(otherResponseFilesData["nowarn"].Distinct().ToList()),
                GenerateAnalyserItemGroup(RetrieveRoslynAnalyzers(assembly, otherResponseFilesData)),
                GenerateAnalyserAdditionalFiles(otherResponseFilesData["additionalfile"].SelectMany(x => x.Split(';')).Distinct().ToArray()),
                GenerateRoslynAnalyzerRulesetPath(assembly, otherResponseFilesData),
                GenerateWarningLevel(otherResponseFilesData["warn"].Concat(otherResponseFilesData["w"]).Distinct()),
                GenerateWarningAsError(otherResponseFilesData["warnaserror"], otherResponseFilesData["warnaserror-"], otherResponseFilesData["warnaserror+"]),
                GenerateDocumentationFile(otherResponseFilesData["doc"].ToArray()),
                GenerateNullable(otherResponseFilesData["nullable"])
            };

            try
            {
                return(string.Format(GetProjectHeaderTemplate(), arguments));
            }
            catch (Exception)
            {
                throw new NotSupportedException(
                          "Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " +
                          arguments.Length);
            }
        }
Esempio n. 8
0
        string[] RetrieveRoslynAnalyzers(ProjectPart assembly, ILookup <string, string> otherResponseFilesData)
        {
#if UNITY_2020_2_OR_NEWER
            return(otherResponseFilesData["analyzer"].Concat(otherResponseFilesData["a"])
                   .SelectMany(x => x.Split(';'))
#if !ROSLYN_ANALYZER_FIX
                   .Concat(m_AssemblyNameProvider.GetRoslynAnalyzerPaths())
#else
                   .Concat(assembly.CompilerOptions.RoslynAnalyzerDllPaths)
#endif
                   .Select(MakeAbsolutePath)
                   .Distinct()
                   .ToArray());
#else
            return(otherResponseFilesData["analyzer"].Concat(otherResponseFilesData["a"])
                   .SelectMany(x => x.Split(';'))
                   .Distinct()
                   .Select(MakeAbsolutePath)
                   .ToArray());
#endif
        }
 private string ProjectFile(ProjectPart projectPart)
 {
     return(Path.Combine(ProjectDirectory, $"{m_AssemblyNameProvider.GetProjectName(projectPart.OutputPath, projectPart.Name)}.csproj"));
 }