public void GenerateUnitTestsLogic(List <string> projClasses) { var dte = (DTE2)Microsoft.VisualStudio.Shell.ServiceProvider .GlobalProvider.GetService(typeof(EnvDTE.DTE)); var selectedProjectName = GetSelectedProjectName(dte); var unitTestProjectName = string.Format("{0}_Tests", selectedProjectName); // discover solution/project types and create an object factory var solutionFullPath = GetSolutionFullPath(dte); // generate unit tests for the analyzed project var generatedTestClassesDirectory = CreateUnitTestsProject(dte, unitTestProjectName); string packagesPath = GetSolutionPackagesFolder(dte); var unitTestGenerator = new UnitTestGenerator(generatedTestClassesDirectory, packagesPath, selectedProjectName); List <string> testClasses = unitTestGenerator.GenerateUnitTestsForClass(solutionFullPath, unitTestProjectName, projClasses); // add test classes to project string csprojPath = string.Format(@"{0}\\{1}\\{2}{3}", GetSolutionPath(dte), unitTestProjectName, unitTestProjectName, ".csproj"); var p = new Microsoft.Build.Evaluation.Project(csprojPath); foreach (string generatedTestClass in testClasses) { p.AddItem("Compile", generatedTestClass); } p.Save(); }
public ArrayList SetCompileItems(ArrayList L) { Microsoft.Build.Evaluation.Project pc = new Microsoft.Build.Evaluation.Project(FileName); if (pc == null) { return(L); } string s = Path.GetDirectoryName(FileName); ArrayList R = GetItems(pc, "Compile", false); foreach (string p in L) { string refs = GetRelativePath(s, p); int i = R.IndexOf(refs); if (i < 0) { pc.AddItem("Compile", refs); } } pc.Save(FileName); pc.ProjectCollection.UnloadAllProjects(); return(L); }
public static void AngularExist() { pathToAngularProject = Directory.GetDirectories(rootFolderPath + "/angular/")[0]; projectAngularName = pathToAngularProject.Remove(0, pathToAngularProject.LastIndexOf('/') + 1); pathToIndexFile = pathToAngularProject + "/dist/index.html"; string csproj = File.ReadAllText(rootFolderPath + "/" + webProjectName + ".csproj"); if (!csproj.Contains(@"angular\" + webProjectName + @"\dist\*.*")) { var p = new Microsoft.Build.Evaluation.Project(rootFolderPath + "/" + webProjectName + ".csproj"); p.AddItem("Content", @"angular\" + webProjectName + @"\dist\*.*"); p.Save(); } watcherDist.Path = pathToAngularProject; watcherDist.EnableRaisingEvents = true; if (Directory.Exists(pathToAngularProject + "/dist")) { if (File.Exists(pathToIndexFile)) { CopyIndex(); } } }
static private void GenerateTest(string featureFilePath, string outputDirectory) { InputGenerator input = new InputGenerator(); var features = input.Load(File.ReadAllLines(featureFilePath)); WriteFile(new HeaderGenerator(), features, outputDirectory, ".h", "UNIT TEST HEADER"); WriteFile(new CodeBehindGenerator(), features, outputDirectory, "_scenarios.cpp", "SCENARIOS CPP"); if (!_singleFile) { AddStepDefinitonToIntelliSenseProject(features, featureFilePath, CS_PROJ); } WriteFileStepDefinition(features, outputDirectory); if (!_singleFile) { AddFeatureFileLinkToIntelliSenseProject(featureFilePath, FEATURE_DIR, CS_PROJ); if (_isDirtyCppProj) { _cppProj.Save(); } if (_isDirtyCsProj) { _csProj.Save(); } } }
/// <summary> /// Adds new category after clicking a button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddNewCategoryButton_Click(object sender, RoutedEventArgs e) { string polishNameOfCategory = PolishNameTextBox.Text; string englishNameOfCategory = EnglishNameTextBox.Text; if (polishNameOfCategory == "Polska" || polishNameOfCategory == null || englishNameOfCategory == "Angielska" || englishNameOfCategory == null) { MessageBox.Show("Nie zostały podane wszystkie potrzebne dane."); } else { string nameOfTextFile = englishNameOfCategory.ToLower() + ".txt"; string foo = "..\\..\\"; string pathToTextFile = foo + nameOfTextFile; try { FileStream fileStream = new FileStream(@pathToTextFile, FileMode.CreateNew, FileAccess.Write); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (File.Exists(@pathToTextFile)) { var build = new Microsoft.Build.Evaluation.Project(@"..\\..\\Fiszki.csproj"); build.AddItem("Resource", nameOfTextFile); build.Save(); Directory.CreateDirectory(@"..\\..\\Photos\\" + englishNameOfCategory); FileStream fileStream = new FileStream(@"..\\..\\myOwnCategories.txt", FileMode.Open, FileAccess.ReadWrite); try { using (StreamWriter sw = new StreamWriter(fileStream)) { sw.BaseStream.Seek(0, SeekOrigin.End); sw.WriteLine(polishNameOfCategory + " " + englishNameOfCategory); sw.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } MessageBoxResult result = MessageBox.Show("Dodano kategorię o nazwie: " + polishNameOfCategory + ". Jeśli chcesz dodać następną kategorię, naciśnij tak, a jeśli chcesz wrócić do menu, naciśnij nie.", "Fiszki", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { setPage = new SetPage(5, MessageBoxResult.Yes); } else { PolishNameTextBox.Name = "Polska"; EnglishNameTextBox.Name = "Angielska"; } }
public bool Install(Microsoft.Build.Evaluation.Project project, string toolsPath) { var projectDir = Path.GetDirectoryName(project.FullPath); _Logger.LogInfo(string.Format("Project Dir is: {0}", projectDir)); var globalPropsFileName = "DnnPackager.props"; var toolsDir = toolsPath.TrimEnd(new char[] { '\\', '/' }); var globalPropsFilePath = Path.Combine(toolsDir, globalPropsFileName); EnsureImport(project, globalPropsFilePath); var projectPropsFileName = "DnnPackageBuilderOverrides.props"; var projectPropsFilePath = Path.Combine(projectDir, projectPropsFileName); EnsureImport(project, projectPropsFilePath); var targetsFileName = "dnnpackager.targets"; var targetsFilePath = Path.Combine(toolsDir, targetsFileName); EnsureImport(project, targetsFilePath); // remove legacy imports. RemoveImport(project, "DnnPackager.Build.targets"); // if octopack targets are there ensure they are added after other targets. ReImportTargetIfExists(project, "OctoPack.targets"); project.Save(project.FullPath); return(true); }
public void RemoveReference(VSProjectItem p) { if (p.ItemType != "Reference") { return; } Microsoft.Build.Evaluation.Project pc = new Microsoft.Build.Evaluation.Project(FileName); if (pc == null) { return; } ICollection <Microsoft.Build.Evaluation.ProjectItem> c = pc.GetItemsByEvaluatedInclude(p.Include); foreach (Microsoft.Build.Evaluation.ProjectItem pp in c) { if (pp.ItemType == "Reference") { pc.RemoveItem(pp); } } pc.Save(FileName); pc.ProjectCollection.UnloadAllProjects(); }
/// <summary> /// Saves a .props file for the specified package, containing the xenko version (only Major.Minor) /// used to compile the package. /// </summary> /// <param name="package">The package.</param> public static void SaveProperties(Package package) { // Props file is in the same folder as the xkpkg file, just with a ".props" extension. var packagePath = package.FullPath; var propsFilePath = UPath.Combine(packagePath.GetParent(), (UFile)(packagePath.GetFileNameWithoutExtension() + ".props")); var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection(); var project = new Microsoft.Build.Evaluation.Project(projectCollection); var commonPropertyGroup = project.Xml.AddPropertyGroup(); var dependencies = package.FindDependencies(false, false, true); // Add Xenko version var xkVersion = dependencies.FirstOrDefault(d => d.Meta.Name == "Xenko"); if (xkVersion != null) { var versionText = xkVersion.Meta.Version.Version.Major + "." + xkVersion.Meta.Version.Version.Minor; commonPropertyGroup.AddProperty("SiliconStudioPackageXenkoVersion", versionText); } if (File.Exists(propsFilePath)) { File.Delete(propsFilePath); } project.Save(propsFilePath); }
private static bool CreateTodaysClassIfNeeded() { var day = ForceDay ?? DateTime.Now.Day; var year = DateTime.Now.Year; var className = GetClassName(); var projectDirectory = GetBaseDirectory(); var classFilename = $"{className}.cs"; var classFileFullPath = Path.Combine(projectDirectory, classFilename); var puzzleFilename = $"input{day:00}.txt"; var puzzleFileFullPath = Path.Combine(projectDirectory, puzzleFilename); if (File.Exists(classFileFullPath)) { return(false); } Console.WriteLine($"{classFilename} not found, will create."); var classContempt = DayTemplate.Replace("#day#", $"{day:00}"); File.WriteAllText(classFileFullPath, classContempt); AddToGit(projectDirectory, classFilename); Console.WriteLine($"{classFilename} created and added to git"); Console.Write($"Fetching puzzle input..."); try { var puzzleContent = GetPuzzleInput(year, day); Console.WriteLine($" done."); File.WriteAllText(puzzleFileFullPath, puzzleContent.Trim()); AddToGit(projectDirectory, puzzleFilename); Console.WriteLine($"{puzzleFilename} created and added to git"); } catch (Exception e) { Console.WriteLine($" failed: {e.Message}"); File.WriteAllText(puzzleFileFullPath, ""); AddToGit(projectDirectory, puzzleFilename); Console.WriteLine($"Created empty {puzzleFilename} and added to git"); } var projectFile = Path.Combine(projectDirectory, "AdventOfCode2020.csproj"); var p = new Microsoft.Build.Evaluation.Project(projectFile); p.AddItem("Compile", classFilename); var kvp = new KeyValuePair <string, string>("CopyToOutputDirectory", "PreserveNewest"); p.AddItem("Content", puzzleFilename, new [] { kvp }); p.Save(); Console.WriteLine($"Class and data files created. Execution halted. Please edit {classFilename} and then run again."); return(true); }
private static void Test_Microsoft_Build_Evaluation() { var p = new Microsoft.Build.Evaluation.Project ( //"/Projects/hw-tools/SampleProjectKreator/samples/App.XamarinAndroid/App.XamarinAndroid.csproj" "/Projects/hw-tools/SampleProjectKreator/samples/Bindings.Sample.Project.Kreator.App.Console.Mono/Bindings.Sample.Project.Kreator.App.Console.Mono.csproj" ); p.AddItem("Compile", @"C:\folder\file.cs"); p.Save(); }
private static void AddFileToProject(string workingDirectory, string generatedClassFileName) { // todo: get csproj file name dynamically // Error in Microsoft.Build: InternalErrorException: https://github.com/Microsoft/msbuild/issues/1889 --> Solution: Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012 var project = new Microsoft.Build.Evaluation.Project(Path.Combine(workingDirectory, "XmlToCode.csproj")); if (project.Items.FirstOrDefault(i => i.EvaluatedInclude == generatedClassFileName) == null) { project.AddItem("Compile", generatedClassFileName); project.Save(); } }
private void AddFileToProject(Microsoft.Build.Evaluation.Project project, string filePath) { try { LogAndDisplay("Adding new files to project: " + project.DirectoryPath + Environment.NewLine + filePath); project.AddItem("Compile", filePath); project.Save(); } catch (Exception ex) { LogAndDisplay("Failed to add file to project:" + Environment.NewLine + project.DirectoryPath + Environment.NewLine + filePath); LogError(ex.Message); } }
private static void UpdateProjectFile(string projectFilePath, int?newValue) { var project = new Microsoft.Build.Evaluation.Project(projectFilePath); var property = project.GetProperty("ApplicationRevision"); if (newValue.HasValue) { property.UnevaluatedValue = newValue.Value.ToString(); } else { property.UnevaluatedValue = (System.Int32.Parse(property.EvaluatedValue) + 1).ToString(); } project.Save(); }
internal static void CreateJsonFile(string jsonToWrite, string jsonFileName) { try { var jsonFile = Path.Combine(DirectoryHandler.DirectoryCreation(Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "UFHtmlExtractor")), jsonFileName + ".json"); File.WriteAllText(jsonFile, jsonToWrite, Encoding.UTF8); var projFilePath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; var p1 = new Microsoft.Build.Evaluation.Project(Path.Combine(projFilePath, Path.GetFileName(projFilePath.TrimEnd(Path.DirectorySeparatorChar)) + ".csproj")); p1.AddItem("None", Path.Combine("UFHtmlExtractor", jsonFileName + ".json")); p1.Save(); } catch (Exception ex) { Console.WriteLine("Creation of Json File, Failed!"); } }
public void CreateFolder(string folder, VSProjectItem ps) { Microsoft.Build.Evaluation.Project pc = new Microsoft.Build.Evaluation.Project(FileName); if (pc == null) { return; } string s = Path.GetDirectoryName(FileName); ArrayList R = GetItems(pc, "Folder", false); if (ps == null || ps.ItemType != "Folder") { string refs = GetRelativePath(s, folder); int i = R.IndexOf(refs); if (i < 0) { pc.AddItem("Folder", refs); } } else { string g = ps.Include; g = g + "\\" + folder; string refs = GetRelativePath(s, g); int i = R.IndexOf(refs); if (i < 0) { pc.AddItem("Folder", refs); } } pc.Save(FileName); pc.ProjectCollection.UnloadAllProjects(); }
public void Add(IEnumerable <TypingsFile> files) { var updated = false; var project = new Microsoft.Build.Evaluation.Project(_projectFileFullPath); foreach (var file in files) { var relativePath = GetRelativePath(file); if (project.Items.FirstOrDefault(i => i.EvaluatedInclude == relativePath) == null) { updated = true; project.AddItem("TypeScriptCompile", relativePath); } } if (updated) { project.Save(); } }
public static void Finalise() { //AutomateAddFile.IncludeInProject(FilesToInclude); if (FilesToInclude != null && FilesToInclude.Count > 0) { var projFilePath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; var p1 = new Microsoft.Build.Evaluation.Project(Path.Combine(projFilePath, Path.GetFileName(System.Reflection.Assembly.GetCallingAssembly().Location).Replace(".dll", "") + ".csproj")); foreach (string filePath in FilesToInclude) { p1.AddItem("Compile", filePath + ".cs"); } p1.Save(); } else { Console.WriteLine("Either Unified Code Generation Intiate functionality was not used or no files were generated to include in Project"); } }
public void IncludeProject() { var projFile = new Microsoft.Build.Evaluation.Project(ProjFile); foreach (string file in System.IO.Directory.GetFiles(Directory, "*.feature", SearchOption.AllDirectories)) { var fileName = Path.GetFileName(file); var relativeFilePath = MakeRelative(file, ProjFile).Replace("/", "\\"); var projectItem = projFile.Items.FirstOrDefault(i => i.EvaluatedInclude == relativeFilePath); if (projectItem == null) { projFile.AddItem("None", relativeFilePath, new[] { new KeyValuePair <string, string>("Generator", "SpecFlowSingleFileGenerator"), new KeyValuePair <string, string>("LastGenOutput", $"{fileName}.cs") }); } } projFile.Save(); }
//--------------------------------------------------------------------------- public bool AddFile(string source, string destination) { try { if (!string.IsNullOrEmpty(source) && !source.Equals(destination)) { File.Copy(source, Path.Combine(RootPath, destination)); } string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\", "EvershockGame/EvershockGame.csproj")); var project = new Microsoft.Build.Evaluation.Project(@path); project.AddItem("Content", string.Format(@"Content\{0}", destination.Replace('/', '\\')), new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("CopyToOutputDirectory", "PreserveNewest") }); project.Save(); return(true); } catch (Exception e) { } return(false); }
public void WriteFile(string solutionFilePath) { var projectFileLocation = $"{solutionFilePath}\\{_projectFolderName}"; string fileName = $"{ClassUnderTest}Test.cs"; string filePath = Path.Combine(projectFileLocation, fileName); if (File.Exists(filePath)) { var sb = AppendMethodToFile(filePath); File.WriteAllText(filePath, sb.ToString()); } else { var p = new Microsoft.Build.Evaluation.Project($"{projectFileLocation}\\{_projectName}.csproj"); p.AddItem("Compile", $"{projectFileLocation}\\{fileName}"); p.Save(); var pageContent = TransformText(); File.WriteAllText(filePath, pageContent); } }
public virtual void RunFinished() { try { var proj = item.ContainingProject; var dte = item.DTE; //foreach (var x in proj.Properties.OfType<Property>()) System.Diagnostics.Debugger.Log(1, "Debug", x.Name + "\n"); CopyBin(); ConfigureProject(proj); CopyDemo(); proj.Save(); dte.ExecuteCommand("File.SaveAll", string.Empty); var filename = proj.FullName; var bproj = new Microsoft.Build.Evaluation.Project(filename); var imppath = Path.Combine(MSBuildExtensionsPath, target); if (bproj.Imports.Any(imp => imp.ImportedProject.FullPath == imppath)) { return; // import is already there, so no need to modify project any further. } ModifyWebConfig(); // select project string solutionName = Path.GetFileNameWithoutExtension(dte.Solution.FullName); dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate(); ((EnvDTE80.DTE2)dte).ToolWindows.SolutionExplorer.GetItem(solutionName + @"\" + proj.Name).Select(vsUISelectionType.vsUISelectionTypeSelect); //Because modify the open *.csproj file outside of the IDE will pop up a window to let you reload the file. //IExecute Command to unload the project before modifying the *.csproj file. And reload after the *.csproj has already updated. bproj.Xml.AddImport(imppath); dte.ExecuteCommand("Project.UnloadProject", string.Empty); bproj.Save(); dte.ExecuteCommand("Project.ReloadProject", string.Empty); } catch (Exception ex) { } }
public void SetImportPath(string importPath, Project prj) { object service = null; IVsSolution solution = null; IVsHierarchy hierarchy = null; ProjectImportElement importProject; int?result = 0; service = GetServiceObject(prj.DTE, typeof(IVsSolution)); solution = (IVsSolution)service; result = solution?.GetProjectOfUniqueName(prj.UniqueName, out hierarchy); IVsProject project = (IVsProject)hierarchy; Microsoft.Build.Evaluation.Project msbuildProject = MSBuildProjectFromIVsProject(project); if (msbuildProject == null) { msbuildProject = ForceLoadMSBuildProjectFromIVsProject(project); } importProject = msbuildProject.Xml.AddImport(importPath); importProject.Label = "Shared"; msbuildProject.Save(); UnloadMSbuildProject(msbuildProject); }
/// <summary> /// Adds the users image. /// </summary> private void AddUsersImage() { nameOfCategory = ((ComboBoxItem)CategoryComboBox.SelectedItem).Name; string foo = "..\\..\\Photos\\"; string newPath = foo + nameOfCategory + "\\" + imageName; System.IO.File.Copy(@pathToImage, @newPath); string foo1 = "..\\..\\"; string pathToTextFile = foo1 + nameOfCategory.ToLower() + ".txt"; Encoding enc = Encoding.Default; FileStream file = new FileStream(pathToTextFile, FileMode.Open, FileAccess.Write); try { using (StreamWriter stream = new StreamWriter(file, enc)) { stream.BaseStream.Seek(0, SeekOrigin.End); stream.WriteLine(polishWord + " " + englishWord + " " + newPath); stream.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } var build = new Microsoft.Build.Evaluation.Project(@"..\\..\\Fiszki.csproj"); build.AddItem("Resource", "Photos\\" + nameOfCategory + "\\" + imageName); build.Save(); MessageBox.Show("Dodano słowo " + polishWord + " do kategorii " + nameOfCategory + " , ścieżka zdjęcia: " + newPath); MainPage mainPage = new MainPage(); Application.Current.MainWindow.Content = mainPage; }
private void EnablePackageRestore(Project project) { if (project.IsWebSite() || project.IsJavaScriptProject()) { // Can't do anything with Website // Also, the Javascript Metro project system has some weird bugs // that cause havoc with the package restore mechanism return; } MsBuildProject buildProject = project.AsMSBuildProject(); AddSolutionDirProperty(project, buildProject); AddNuGetTargets(project, buildProject); SetMsBuildProjectProperty(project, buildProject, "RestorePackages", "true"); if (project.IsJavaScriptProject()) { // JavaScript project requires an extra kick // in order to save changes to the project file. // TODO: Check with VS team to ask them to fix buildProject.Save(); } }
public void Save() { _loadedProject.Save(); }
/// <summary> /// Saves a .props file for the specified package, containing the paradox version (only Major.Minor) /// used to compile the package. /// </summary> /// <param name="package">The package.</param> public static void SaveProperties(Package package) { // Props file is in the same folder as the pdxpkg file, just with a ".props" extension. var packagePath = package.FullPath; var propsFilePath = UPath.Combine(packagePath.GetParent(), (UFile)(packagePath.GetFileName() + ".props")) ; var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection(); var project = new Microsoft.Build.Evaluation.Project(projectCollection); var commonPropertyGroup = project.Xml.AddPropertyGroup(); var dependencies = package.FindDependencies(false, false, true); // Add Paradox version var pdxVersion = dependencies.FirstOrDefault(d => d.Meta.Name == "Paradox"); if (pdxVersion != null) { var versionText = pdxVersion.Meta.Version.Version.Major + "." + pdxVersion.Meta.Version.Version.Minor; commonPropertyGroup.AddProperty("SiliconStudioPackageParadoxVersion", versionText); } if (File.Exists(propsFilePath)) { File.Delete(propsFilePath); } project.Save(propsFilePath); }
public static void InterpretCommand(string input) { switch (input.ToLower()) { case "compile": System.Diagnostics.Process.Start("Compiler.bat"); Environment.Exit(0); break; case "test": Test.MainMethod(); break; } string[] args = input.Split(' '); if (input.ToLower().StartsWith("edit")) { if (args.Length > 1) { if (File.Exists(ProjectPath + args[1])) { string[] code = File.ReadAllLines(ProjectPath + args[1]); Editor.LoadCode(ProjectPath + args[1], code); Editor.Show(); } } } else if (input.ToLower().StartsWith("create")) { if (args.Length > 1) { if (!File.Exists(ProjectPath + args[1])) { File.Create(ProjectPath + args[1]); var p = new Microsoft.Build.Evaluation.Project(ProjectPath + "Hal.csproj"); p.AddItem("Compile", ProjectPath + args[1]); p.Save(); } } } else if (input.ToLower().StartsWith("remove")) { if (args.Length > 1) { if (File.Exists(ProjectPath + args[1])) { List <string> csproj = new List <string>(File.ReadAllLines(ProjectPath + "Hal.csproj")); string line = "<Compile Include=\"" + ProjectPath + args[1] + "\" />"; for (int i = 0; i < csproj.Count; i++) { if (csproj[i].Contains(line)) { csproj.RemoveAt(i); } } File.Delete(ProjectPath + args[1]); File.WriteAllLines(ProjectPath + "Hal.csproj", csproj.ToArray()); } } } }