public void TestCsprojDebug() { ProjectFileHelper helper = new ProjectFileHelper("test.csproj"); string config = "debug"; //read tests string DefineConstants = helper.GetProperty("DefineConstants", config); Assert.AreEqual(DefineConstants, "DEBUG;TRACE"); string WarningLevel = helper.GetProperty("WarningLevel", config); Assert.AreEqual(WarningLevel, "7"); //set tests helper.SetProperty("DefineConstants", "Test Debug Defines", config); helper.SetProperty("WarningLevel", "8", config); helper.Save(); helper.Reload(); DefineConstants = helper.GetProperty("DefineConstants", config); Assert.AreEqual(DefineConstants, "Test Debug Defines"); WarningLevel = helper.GetProperty("WarningLevel", config); Assert.AreEqual(WarningLevel, "8"); //reset to default value helper.SetProperty("DefineConstants", "DEBUG;TRACE", config); helper.SetProperty("WarningLevel", "7", config); helper.Save(); }
public List <DepReference> GetPackageReferencesFromProjectFile(string projectPath) { var packageRefs = new List <DepReference>(); var(document, itemGroups) = ProjectFileHelper.LoadProjectXml(projectPath); var refItemGroup = itemGroups.FirstOrDefault(HasReference); var refsOnly = refItemGroup?.Descendants()?.Where(IsReference); if (refsOnly?.Any() == true) { foreach (var @ref in refsOnly) { string hintPath = @ref.Descendants()?.FirstOrDefault(IsHintPath)?.Value; string packageIncludeString = @ref.Attributes().FirstOrDefault(a => a.Name == "Include")?.Value; if (packageIncludeString != null) { var packageRef = new DepReference(packageIncludeString, hintPath); packageRefs.Add(packageRef); } } } return(packageRefs); }
public void TestRelease() { ProjectFileHelper helper = new ProjectFileHelper("test.csproj"); string config = "release"; //read tests string DefineConstants = helper.GetProperty("DefineConstants", config); Assert.AreEqual(DefineConstants, "TRACE"); string WarningLevel = helper.GetProperty("WarningLevel", config); Assert.AreEqual(WarningLevel, "4"); //set tests helper.SetProperty("DefineConstants", "Test Release Defines", config); helper.SetProperty("WarningLevel", "5", config); helper.Save(); helper.Reload(); DefineConstants = helper.GetProperty("DefineConstants", config); Assert.AreEqual(DefineConstants, "Test Release Defines"); WarningLevel = helper.GetProperty("WarningLevel", config); Assert.AreEqual(WarningLevel, "5"); //reset to default value helper.SetProperty("DefineConstants", "TRACE", config); helper.SetProperty("WarningLevel", "4", config); helper.Save(); }
public StaticModelType(string sourceFileName) { _projectFileHelper = new ProjectFileHelper(); _variableNameHelper = new VariableNameHelper(); _sourceFileName = sourceFileName; }
private void ActOnProject(Config config, string filePath) { Vlog(filePath); var(document, itemGroups) = ProjectFileHelper.LoadProjectXml(filePath); var shouldSave = ActOnProject(config, ref itemGroups); if (shouldSave) { var originalBytes = File.ReadAllBytes(filePath); byte[] newBytes = null; using (var memoryStream = new MemoryStream()) using (var textWriter = new StreamWriter(memoryStream, Encoding.UTF8)) { document.Save(textWriter, SaveOptions.None); newBytes = memoryStream.ToArray(); } newBytes = SyncBOM(originalBytes, newBytes); if (!AreEqual(originalBytes, newBytes)) { File.WriteAllBytes(filePath, newBytes); } } }
static void Main(string[] args) { //Xml.Definitions.Project project = XmlSerializer.Deserialize(Path); //Xml.Data.Project project = XmlHelper.GetProject(Path); ProjectFileHelper.OrderResourcesByName(Path, OutputPath); Console.ReadLine(); }
public void Execute(object parameter) { MessageBoxResult result = MessageBox.Show("Are you sure you want to save your project?", "Save project to file", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { ProjectFileHelper.SaveProjectToFile(ViewModel.Project); } }
public UnitTest(string targetAssemblyNameParam, string targetTypeName, string unitTestFileName = "") { _typeHelper = new TypeHelper(); _projectFileHelper = new ProjectFileHelper(); _variableNameHelper = new VariableNameHelper(); _targetAssemblyNameParam = targetAssemblyNameParam; _targetTypeName = targetTypeName; _unitTestFileName = unitTestFileName; }
protected override (bool isSuccess, SError error) HandleProject(Config config, string repoPath, string projectPath) { // TODO: setting to warn of duplicates when treating git files in a case-insensitive manner . . . // Because `thing.txt` and `Thing.txt` could theoretically both exist . . . HashSet <string> filesTrackedByGit = GitHelper.GetFilesFromGitForProject(repoPath, projectPath); HashSet <string> filesIncludedInProjectFile = ProjectFileHelper.GetFilesFromProjectFile(projectPath, out HashSet <string> duplicates); string projectName = ProjectFileHelper.GetProjectFileName(projectPath); // Filter out project files, because project files do not include themselves . . . var self = FileHelper.NormalizePath(Path.GetRelativePath(repoPath, projectPath)); filesTrackedByGit.Remove(self); // Remove any other files our config says we can ignore before we compare . . . filesTrackedByGit.RemoveWhere(config.IsIgnorable); // Project files are case-insensitive . . . // But git is case-sensitive . . . var filesNotIncludedInProjectFile = filesTrackedByGit.Where(m => !filesIncludedInProjectFile.Contains(m, StringComparer.CurrentCultureIgnoreCase)).ToList(); if (filesNotIncludedInProjectFile?.Any() == true) { _errorOccurred = true; Log($"{projectName}:"); foreach (var file in filesNotIncludedInProjectFile) { LogError($" ({Ordinal}) \t{file}", includePrefix: false); Ordinal++; } NL(); } else { Log($"'{projectName}' is not missing any files."); NL(); } if (ShouldCheckForDuplicates) { if (duplicates?.Any() == true) { Log($"{projectName}:"); foreach (var duplicate in duplicates) { LogError($" ({Ordinal}) \t DUPLICATE {duplicate}", includePrefix: false); Ordinal++; } } } return(Success); }
public ProjectExplorerWindowViewModel() { Projects = new List <Project>(); LoadProjectCommand = new LoadProjectCommand(this); string[] files = Directory.GetFiles(ProjectFileHelper.projectSaveFolder); foreach (string filePath in files) { Projects.Add(ProjectFileHelper.ReadProjectFromFile(filePath)); } }
public void Execute(object parameter) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = ProjectFileHelper.projectSaveFolder; openFileDialog.Filter = "ProjectTracker files (*.ptf)|*.ptf"; if (openFileDialog.ShowDialog() == true) { ViewModel.Project = ProjectFileHelper.ReadProjectFromFile(openFileDialog.FileName); } }
public void It_throws_FileNotFoundException_if_GetDefaultNamespace_cannot_find_csproj() { // Arrange Mocks var sb = new StringBuilder(); SystemContext.ConsoleErrorWriteLine = s => sb.Append(s); var directory = Substitute.For <DirectoryInfoBase>(); directory.GetFiles("*.csproj", SearchOption.TopDirectoryOnly).Returns(info => new FileInfoBase[] { }); // Act Action act = () => ProjectFileHelper.GetDefaultNamespace(directory); // Assert act.Should().Throw <FileNotFoundException>(); sb.ToString().Should().Be("No csproj file found for default namespace. Please specify a namespace as a command argument."); }
public void Execute(object parameter) { if (ViewModel.TaskWorkedOn != null) { MessageBox.Show("You are currently working on: " + ViewModel.TaskWorkedOn.Name + "\nFinish your current work before closing the project"); } else { if (MessageBox.Show("Are you sure you want to close the project?", "Close project", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { ProjectFileHelper.SaveProjectToFile(ViewModel.LoadedProject); ViewModel.LoadedProject = null; ViewModel.SelectedTask = null; ViewModel.TaskWorkedOn = null; } } }
public void It_can_GetDefaultNamespace_even_if_the_rootNamespace_is_not_found_in_csproj() { // Arrange Mocks var filesystem = Substitute.For <IFileSystem>(); var directory = Substitute.For <DirectoryInfoBase>(); var result1 = Substitute.For <FileInfoBase>(); var filecontent = "Sorry no namespace here"; directory.GetFiles("*.csproj", SearchOption.TopDirectoryOnly).Returns(info => new[] { result1 }); result1.OpenRead().Returns(info => StringToStream(filecontent)); result1.Name.Returns("bar.csproj"); filesystem.Path.GetFileNameWithoutExtension("bar.csproj").Returns("bar"); // Act var result = ProjectFileHelper.GetDefaultNamespace(directory); // Assert result.Should().Be("bar"); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Usage:killpdb <something.sln>"); } else { //https://stackoverflow.com/questions/707107/parsing-visual-studio-solution-files var solutionFile = SolutionFile.Parse(Path.GetFullPath(args[0])); var projList = solutionFile.ProjectsInOrder.ToList(); var configList = new string[] { "Debug", "Release" }; foreach (var prj in projList) { //<GenerateDebugInformation>true</GenerateDebugInformation> try { bool changed = false; var path = Path.GetExtension(prj.RelativePath); if (path.Equals(".vcxproj")) { ProjectFileHelper helper = new ProjectFileHelper(prj.RelativePath); var cnt = helper.SetAllProperty("GenerateDebugInformation", "false"); Console.WriteLine($"{prj.ProjectName} => {cnt} "); if (cnt > 0) { helper.Save(); } } else { } } catch (Exception e) { Console.WriteLine(e); throw; } } } }
public void TestCsprojGlobal() { ProjectFileHelper helper = new ProjectFileHelper("test.csproj"); string config = "debug"; //read tests string AssemblyName = helper.GetProperty("AssemblyName", config); Assert.AreEqual(AssemblyName, "AppExeName"); string RootNamespace = helper.GetProperty("RootNamespace", config); Assert.AreEqual(RootNamespace, "Com.App.Desktop"); string PublishUrl = helper.GetProperty("PublishUrl", config); Assert.AreEqual(PublishUrl, "publish\\"); //set tests helper.SetProperty("AssemblyName", "test assmbly name", config); helper.SetProperty("RootNamespace", "test root namespace", config); helper.SetProperty("PublishUrl", "test publish urls", config); helper.Save(); helper.Reload(); AssemblyName = helper.GetProperty("AssemblyName", config); Assert.AreEqual(AssemblyName, "test assmbly name"); RootNamespace = helper.GetProperty("RootNamespace", config); Assert.AreEqual(RootNamespace, "test root namespace"); PublishUrl = helper.GetProperty("PublishUrl", config); Assert.AreEqual(PublishUrl, "test publish urls"); //reset to default value helper.SetProperty("AssemblyName", "AppExeName", config); helper.SetProperty("RootNamespace", "Com.App.Desktop", config); helper.SetProperty("PublishUrl", "publish\\", config); helper.Save(); }
public void It_can_GetDefaultNamespace_even_if_it_finds_too_many_csproj_files() { // Arrange Mocks var sb = new StringBuilder(); SystemContext.ConsoleWriteLine = s => sb.Append(s); var directory = Substitute.For <DirectoryInfoBase>(); var result1 = Substitute.For <FileInfoBase>(); var result2 = Substitute.For <FileInfoBase>(); var filecontent = "<RootNamespace>Foo</RootNamespace>"; directory.GetFiles("*.csproj", SearchOption.TopDirectoryOnly).Returns(info => new[] { result1, result2 }); result1.OpenRead().Returns(info => StringToStream(filecontent)); // Act var result = ProjectFileHelper.GetDefaultNamespace(directory); // Assert result.Should().Be("Foo"); sb.ToString().Should().Be("Multiple csproj files found for namespace, using the first one."); }
public void TestVcxprojReleaseX64() { ProjectFileHelper helper = new ProjectFileHelper("cpulspuls.vcxproj"); string config = "release"; string platform = "x64"; //read tests string def = helper.GetProperty("PreprocessorDefinitions", config, platform); string newdef = "DX_11_M;" + def; //set tests helper.SetProperty("PreprocessorDefinitions", newdef, config, platform); helper.Save(); helper.Reload(); string rdef = helper.GetProperty("PreprocessorDefinitions", config, platform); Assert.AreEqual(rdef, newdef); }
protected override (bool isSuccess, SError error) HandleProject(Config config, string repoPath, string projectPath) { ProjectFileHelper.GetProjectFileParentDirName(projectPath, out string absoluteProjectFileParentDirPath); var projName = ProjectFileHelper.GetProjectFileName(projectPath); var packageRefs = GetPackageReferencesFromProjectFile(projectPath); var packagesConf = GetPackagesFromPackagesDotConfig(projectPath); if (ShouldLookForPackagesMissingFromProjectFile) { var missingPackages = packagesConf.Where(p => !packageRefs.Any(r => r.Name == p.Name)); if (missingPackages?.Any() == true) { Log($"'{projName}' project file missing references:"); foreach (var missingPackage in missingPackages) { Log($"\t{missingPackage.Name}.{missingPackage.Version}"); NumMissing++; } NL(); } } var primaryDependencies = packageRefs.Where(p => packagesConf.Any(c => c.Name == p.Name)); if (ShouldPrintPotentialHintPathDiscrepancies) { foreach (var primaryDep in primaryDependencies) { var relevantConf = packagesConf.First(c => c.Name == primaryDep.Name); var projectedHintPath = relevantConf.ProjectHintPath(config); var hintPath = primaryDep.HintPath?.Path; bool hasHintPath = hintPath != null; if (hasHintPath && ShouldCheckPackagesOnDisk) { // HintPaths are relative, so we need to make the path absolute . . . string absoluteHintPath = Path.GetFullPath(hintPath, absoluteProjectFileParentDirPath); if (!File.Exists(absoluteHintPath)) { AddMissingPackageOccurrence(absoluteHintPath, projName); } } bool isFine = true; if (hasHintPath && !string.Equals(hintPath, projectedHintPath, StringComparison.InvariantCultureIgnoreCase)) { if (ShouldIgnoreTargetFrameworks) { var agnosticHintPath = MakeAgnosticHintPath(hintPath, primaryDep.Name); var agnosticProjectedPath = MakeAgnosticHintPath(projectedHintPath, relevantConf.Name); if (string.Equals(agnosticHintPath, agnosticProjectedPath, StringComparison.InvariantCultureIgnoreCase)) { goto isFineHandler; } } isFine = false; NumDiscrepancies++; Log($"{projName}'s '{primaryDep.Name}':"); Log("HP:\t" + hintPath); Log("GP:\t" + projectedHintPath); NL(); } else if (!hasHintPath) { isFine = false; Log($"{projName}'s '{primaryDep.Name}' has no hint path"); NL(); NumNoHPs++; } isFineHandler: if (isFine) { NumFine++; } } } return(Success); }
public void SetUp() { helper = new ProjectFileHelper("*.csprojfortest"); }
public void SetUp() { testee = new ProjectFileHelper("*.csprojfortest"); result = new ValidationResult(null); }