private string ProjectHeader(
            Assembly assembly,
            IEnumerable <ResponseFileData> responseFilesData,
            string[] roslynAnalyzerDllPaths
            )
        {
            var          toolsVersion   = "4.0";
            var          productVersion = "10.0.20506";
            const string baseDirectory  = ".";

            var targetFrameworkVersion = "v4.7.1";
            var targetLanguageVersion  = "latest";            // danger: latest is not the same absolute value depending on the VS version.

            if (m_CurrentInstallation != null)
            {
                var vsLanguageSupport    = m_CurrentInstallation.LatestLanguageVersionSupported;
                var unityLanguageSupport = UnityInstallation.LatestLanguageVersionSupported(assembly);

                // Use the minimal supported version between VS and Unity, so that compilation will work in both
                targetLanguageVersion = (vsLanguageSupport <= unityLanguageSupport ? vsLanguageSupport : unityLanguageSupport).ToString(2);                 // (major, minor) only
            }

            var projectType = ProjectTypeOf(assembly.name);

            var arguments = new object[]
            {
                toolsVersion,
                productVersion,
                ProjectGuid(assembly),
                XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEngineAssemblyPath())),
                XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEditorAssemblyPath())),
                string.Join(";", assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
                MSBuildNamespaceUri,
                assembly.name,
                assembly.outputPath,
                GetRootNamespace(assembly),
                targetFrameworkVersion,
                targetLanguageVersion,
                baseDirectory,
                assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
                // flavoring
                projectType + ":" + (int)projectType,
                EditorUserBuildSettings.activeBuildTarget + ":" + (int)EditorUserBuildSettings.activeBuildTarget,
                Application.unityVersion,
                VisualStudioIntegration.PackageVersion()
            };

            try
            {
#if UNITY_2020_2_OR_NEWER
                return(string.Format(GetProjectHeaderTemplate(roslynAnalyzerDllPaths, assembly.compilerOptions.RoslynAnalyzerRulesetPath), arguments));
#else
                return(string.Format(GetProjectHeaderTemplate(Array.Empty <string>(), null), arguments));
#endif
            }
            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);
            }
        }
Пример #2
0
        string ProjectHeader(
            Assembly assembly,
            IEnumerable <ResponseFileData> responseFilesData
            )
        {
            var          toolsVersion   = "4.0";
            var          productVersion = "10.0.20506";
            const string baseDirectory  = ".";

            var targetFrameworkVersion = "v4.7.1";
            var targetLanguageVersion  = "latest"; // danger: latest is not the same absolute value depending on the VS version.

            if (m_CurrentInstallation != null && m_CurrentInstallation.SupportsCSharp8)
            {
                // Current VS installation is compatible with C# 8.

#if !UNITY_2020_2_OR_NEWER
                // Unity 2020.2.0a12 added support for C# 8
                // <=2020.1 has no support for C# 8 constructs, so tell the compiler to accept only C# 7.3 or lower.
                targetLanguageVersion = "7.3";
#endif
            }

            var projectType = ProjectTypeOf(assembly.name);

            var arguments = new object[]
            {
                toolsVersion,
                productVersion,
                ProjectGuid(assembly),
                XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEngineAssemblyPath())),
                XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEditorAssemblyPath())),
                string.Join(";", assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
                MSBuildNamespaceUri,
                assembly.name,
                assembly.outputPath,
                GetRootNamespace(assembly),
                targetFrameworkVersion,
                targetLanguageVersion,
                baseDirectory,
                assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
                // flavoring
                projectType + ":" + (int)projectType,
                EditorUserBuildSettings.activeBuildTarget + ":" + (int)EditorUserBuildSettings.activeBuildTarget,
                Application.unityVersion,
                VisualStudioIntegration.PackageVersion()
            };

            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);
            }
        }
Пример #3
0
        private string ProjectHeader(
            Assembly assembly,
            ResponseFileData[] responseFilesData
            )
        {
            var    projectType = ProjectTypeOf(assembly.name);
            string rulesetPath = null;
            var    analyzers   = Array.Empty <string>();

            if (m_CurrentInstallation != null && m_CurrentInstallation.SupportsAnalyzers)
            {
                analyzers = m_CurrentInstallation.GetAnalyzers();
#if UNITY_2020_2_OR_NEWER
                analyzers = analyzers != null?analyzers.Concat(assembly.compilerOptions.RoslynAnalyzerDllPaths).ToArray() : assembly.compilerOptions.RoslynAnalyzerDllPaths;

                rulesetPath = assembly.compilerOptions.RoslynAnalyzerRulesetPath;
#endif
            }

            var projectProperties = new ProjectProperties()
            {
                ProjectGuid   = ProjectGuid(assembly),
                LangVersion   = GetLangVersion(assembly),
                AssemblyName  = assembly.name,
                RootNamespace = GetRootNamespace(assembly),
                OutputPath    = assembly.outputPath,
                // Analyzers
                Analyzers   = analyzers,
                RulesetPath = rulesetPath,
                // RSP alterable
                Defines = assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray(),
                Unsafe  = assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
                // VSTU Flavoring
                FlavoringProjectType    = projectType + ":" + (int)projectType,
                FlavoringBuildTarget    = EditorUserBuildSettings.activeBuildTarget + ":" + (int)EditorUserBuildSettings.activeBuildTarget,
                FlavoringUnityVersion   = Application.unityVersion,
                FlavoringPackageVersion = VisualStudioIntegration.PackageVersion(),
            };

            return(GetProjectHeader(projectProperties));
        }