Visual studio et csharp

De Banane Atomic
Aller à la navigationAller à la recherche

Modifier un projet

Csharp.svg
var collection = new ProjectCollection();
var project = collection.LoadProject(projectFilePath);

project.SetProperty("SignAssembly", "true");
project.SetProperty("AssemblyOriginatorKeyFile", relativePathToKey);
// <PropertyGroup>
//    <SignAssembly>true</SignAssembly>
//    <AssemblyOriginatorKeyFile>..\relativePathToKey\clé.pfx</AssemblyOriginatorKeyFile>

var metadata = new Dictionary<string, string>();
metadata["Link"] = "clé.pfx";
project.AddItem("None", relativePathToKey, metadata);
//   <ItemGroup>
//    <None Include="..\relativePathToKey\clé.pfx">
//      <Link>clé.pfx</Link>
//    </None>

project.Save(projectFilePath);

Lister les projets d'un fichier sln

Csharp.svg
using JetBrains.ProjectModel.SolutionFileParser; // assembly: JetBrains.Platform.ProjectModel.dll
using JetBrains.Util; // assembly: JetBrains.Platform.Util
// assembly: JetBrains.Platform.Interop.WinApi ?

public static IEnumerable<string> GetProjects(string solutionFilePath)
{
    // SolutionFileParser.ParseFile is depracated
    // JetBrains.Application.SinceClr4.BuildScript.Compile.SolutionFileParser.Parser.Solution.Parse();

    var slnFile = SolutionFileParser.ParseFile(FileSystemPath.Parse(solutionFilePath));
    foreach (var project in slnFile.Projects)
    {
        if (project.GetLocation().FileAccessPath.EndsWith("csproj"))
        {
            yield return project.GetLocation().FileAccessPath;
        }
        /* */
        Console.WriteLine(project.ProjectName);
        Console.WriteLine(project.ProjectGuid);
        Console.WriteLine(project.ProjectTypeGuid);
        foreach (var kvp in project.ProjectSections)
        {
            Console.WriteLine(kvp.Key);
            foreach (var projectSection in kvp.Value)
            {
                Console.WriteLine(projectSection.SectionName);
                Console.WriteLine(projectSection.SectionValue);
                foreach (var kvpp in projectSection.Properties)
                {
                    Console.WriteLine(kvpp.Key);
                    Console.WriteLine(string.Join(",", kvpp.Value));
                }
            }
        }
    }
}