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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        IEnumerable <SolutionProjectEntry> ToProjectEntries(IEnumerable <Assembly> assemblies)
        {
            foreach (var assembly in assemblies)
            {
                yield return new SolutionProjectEntry()
                       {
                           ProjectFactoryGuid = SolutionGuid(assembly),
                           Name        = assembly.name,
                           FileName    = Path.GetFileName(ProjectFile(assembly)),
                           ProjectGuid = ProjectGuid(assembly),
                           Metadata    = k_WindowsNewline
                       }
            }
            ;
        }

        /// <summary>
        /// Generate the active configuration string for a given project guid
        /// </summary>
        string GetProjectActiveConfigurations(string projectGuid)
        {
            return(string.Format(
                       m_SolutionProjectConfigurationTemplate,
                       projectGuid));
        }

        string EscapedRelativePathFor(string file)
        {
            var projectDir = FileUtility.Normalize(ProjectDirectory);

            file = FileUtility.Normalize(file);
            var path = SkipPathPrefix(file, projectDir);

            var packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.Replace('\\', '/'));

            if (packageInfo != null)
            {
                // We have to normalize the path, because the PackageManagerRemapper assumes
                // dir seperators will be os specific.
                var absolutePath = Path.GetFullPath(FileUtility.Normalize(path));

                path = SkipPathPrefix(absolutePath, projectDir);
            }

            return(XmlFilename(path));
        }
Exemplo n.º 4
0
        string ProjectHeader(
            Assembly island,
            IEnumerable <ResponseFileData> responseFilesData
            )
        {
            var          toolsVersion   = "4.0";
            var          productVersion = "10.0.20506";
            const string baseDirectory  = ".";

            var targetFrameworkVersion = "v4.7.1";
            var targetLanguageVersion  = "latest";

            var projectType = ProjectTypeOf(island.outputPath);

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

            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 EscapedRelativePathFor(string file)
        {
            var projectDir = FileUtility.Normalize(ProjectDirectory);

            file = FileUtility.Normalize(file);
            var path = SkipPathPrefix(file, projectDir);

            var packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.Replace('\\', '/'));

            if (packageInfo != null)
            {
                // We have to normalize the path, because the PackageManagerRemapper assumes
                // dir seperators will be os specific.
                var absolutePath = Path.GetFullPath(FileUtility.Normalize(path));

                path = SkipPathPrefix(absolutePath, projectDir);
            }

            return(XmlFilename(path));
        }
Exemplo n.º 6
0
 public string SolutionFile()
 {
     return(Path.Combine(FileUtility.Normalize(ProjectDirectory), $"{InvalidCharactersRegexPattern.Replace(m_ProjectName,"_")}.sln"));
 }
 internal string VsConfigFile()
 {
     return(Path.Combine(FileUtility.Normalize(ProjectDirectory), ".vsconfig"));
 }