public static void FindVSWhere() { _vsWherePath = FileUtility .FindPackageAssetFullPath("VSWhere a:packages", "vswhere.exe") .FirstOrDefault(); }
private string SolutionText(IEnumerable <Assembly> assemblies, Solution previousSolution = null) { const string fileversion = "12.00"; const string vsversion = "15"; var relevantAssemblies = RelevantAssembliesForMode(assemblies); var generatedProjects = ToProjectEntries(relevantAssemblies).ToList(); SolutionProperties[] properties = null; // First, add all projects generated by Unity to the solution var projects = new List <SolutionProjectEntry>(); projects.AddRange(generatedProjects); if (previousSolution != null) { // Add all projects that were previously in the solution and that are not generated by Unity, nor generated in the project root directory var externalProjects = previousSolution.Projects .Where(p => p.IsSolutionFolderProjectFactory() || !FileUtility.IsFileInProjectRootDirectory(p.FileName)) .Where(p => generatedProjects.All(gp => gp.FileName != p.FileName)); projects.AddRange(externalProjects); properties = previousSolution.Properties; } string propertiesText = GetPropertiesText(properties); string projectEntriesText = GetProjectEntriesText(projects); // do not generate configurations for SolutionFolders var configurableProjects = projects.Where(p => !p.IsSolutionFolderProjectFactory()); string projectConfigurationsText = string.Join(k_WindowsNewline, configurableProjects.Select(p => GetProjectActiveConfigurations(p.ProjectGuid)).ToArray()); return(string.Format(GetSolutionText(), fileversion, vsversion, projectEntriesText, projectConfigurationsText, propertiesText)); }
public string SolutionFile() { return(Path.Combine(FileUtility.Normalize(ProjectDirectory), $"{InvalidCharactersRegexPattern.Replace(m_ProjectName,"_")}.sln")); }
public string ProjectFile(Assembly assembly) { return(Path.Combine(ProjectDirectory, $"{FileUtility.FileNameWithoutExtension(assembly.outputPath)}.csproj")); }
string ProjectText(Assembly assembly, Dictionary <string, string> allAssetsProjectParts, IEnumerable <ResponseFileData> responseFilesData, List <Assembly> allProjectIslands) { var projectBuilder = new StringBuilder(ProjectHeader(assembly, responseFilesData)); var references = new List <string>(); var projectReferences = new List <Match>(); projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline); foreach (string file in assembly.sourceFiles) { if (!ShouldFileBePartOfSolution(file)) { continue; } var extension = Path.GetExtension(file).ToLower(); var fullFile = EscapedRelativePathFor(file); if (".dll" != extension) { projectBuilder.Append(" <Compile Include=\"").Append(fullFile).Append("\" />").Append(k_WindowsNewline); } else { references.Add(fullFile); } } projectBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline); var assemblyName = FileUtility.FileNameWithoutExtension(assembly.outputPath); projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline); // Append additional non-script files that should be included in project generation. if (allAssetsProjectParts.TryGetValue(assemblyName, out var additionalAssetsForProject)) { projectBuilder.Append(additionalAssetsForProject); } var islandRefs = references.Union(assembly.allReferences); foreach (string reference in islandRefs) { if (reference.EndsWith("/UnityEditor.dll", StringComparison.Ordinal) || reference.EndsWith("/UnityEngine.dll", StringComparison.Ordinal) || reference.EndsWith("\\UnityEditor.dll", StringComparison.Ordinal) || reference.EndsWith("\\UnityEngine.dll", StringComparison.Ordinal)) { continue; } var match = k_ScriptReferenceExpression.Match(reference); if (match.Success) { // assume csharp language // Add a reference to a project except if it's a reference to a script assembly // that we are not generating a project for. This will be the case for assemblies // coming from .assembly.json files in non-internalized packages. var dllName = match.Groups["dllname"].Value; if (allProjectIslands.Any(i => Path.GetFileName(i.outputPath) == dllName)) { projectReferences.Add(match); continue; } } string fullReference = Path.IsPathRooted(reference) ? reference : Path.Combine(ProjectDirectory, reference); AppendReference(fullReference, projectBuilder); } var responseRefs = responseFilesData.SelectMany(x => x.FullPathReferences.Select(r => r)); foreach (var reference in responseRefs) { AppendReference(reference, projectBuilder); } projectBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline); if (0 < projectReferences.Count) { projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline); foreach (Match reference in projectReferences) { var referencedProject = reference.Groups["project"].Value; projectBuilder.Append(" <ProjectReference Include=\"").Append(referencedProject).Append(GetProjectExtension()).Append("\">").Append(k_WindowsNewline); projectBuilder.Append(" <Project>{").Append(ProjectGuid(Path.Combine("Temp", reference.Groups["project"].Value + ".dll"))).Append("}</Project>").Append(k_WindowsNewline); projectBuilder.Append(" <Name>").Append(referencedProject).Append("</Name>").Append(k_WindowsNewline); projectBuilder.Append(" </ProjectReference>").Append(k_WindowsNewline); } projectBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline); } projectBuilder.Append(ProjectFooter()); return(projectBuilder.ToString()); }
string ProjectGuid(string assembly) { return(SolutionGuidGenerator.GuidForProject(m_ProjectName + FileUtility.FileNameWithoutExtension(assembly))); }
private bool OpenWindowsApp(string path, int line) { var progpath = FileUtility .FindPackageAssetFullPath("COMIntegration a:packages", "COMIntegration.exe") .FirstOrDefault(); if (string.IsNullOrWhiteSpace(progpath)) { return(false); } string absolutePath = ""; if (!string.IsNullOrWhiteSpace(path)) { absolutePath = Path.GetFullPath(path); } // We remove all invalid chars from the solution filename, but we cannot prevent the user from using a specific path for the Unity project // So process the fullpath to make it compatible with VS var solution = GetOrGenerateSolutionFile(path); if (!string.IsNullOrWhiteSpace(solution)) { solution = $"\"{solution}\""; solution = solution.Replace("^", "^^"); } var process = new Process { StartInfo = new ProcessStartInfo { FileName = progpath, Arguments = $"\"{CodeEditor.CurrentEditorInstallation}\" \"{absolutePath}\" {solution} {line}", CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, } }; var result = process.Start(); while (!process.StandardOutput.EndOfStream) { var outputLine = process.StandardOutput.ReadLine(); if (outputLine == "displayProgressBar") { EditorUtility.DisplayProgressBar("Opening Visual Studio", "Starting up Visual Studio, this might take some time.", .5f); } if (outputLine == "clearprogressbar") { EditorUtility.ClearProgressBar(); } } var errorOutput = process.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(errorOutput)) { Console.WriteLine("Error: \n" + errorOutput); } process.WaitForExit(); return(result); }