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);
            }
        }
Ejemplo n.º 2
0
        internal string GetLangVersion(Assembly assembly)
        {
            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
            }

            return(targetLanguageVersion);
        }