You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Richard Stanton edited this page Aug 9, 2024
·
5 revisions
These are some basic samples using the model and serializers.
Convert a solution file to a .slnx solution file.
privatestaticasyncTaskConvertToSlnxAsync(stringfilePath,stringslnxFilePath,CancellationTokencancellationToken){// See if the file is a known solution file.ISolutionSerializer?serializer=SolutionSerializers.GetSerializerByMoniker(filePath);if(serializerisnull){return;}try{SolutionModelsolution=awaitserializer.OpenAsync(filePath,cancellationToken);awaitSolutionSerializers.SlnXml.SaveAsync(slnxFilePath,solution,cancellationToken);}catch(SolutionException){// There was an unrecoverable syntax error reading the solution file.return;}}
Read each project and get project build configurations
privatestaticvoidReadEachProject(SolutionModelsolution){// Pick the first configuration in the solution.stringbuildConfiguration=solution.BuildTypes[0];stringbuildPlatform=solution.Platforms[0];foreach(SolutionProjectModelprojectinsolution.SolutionProjects){stringprojectFilePath=project.FilePath;// Find the project configuration for the solution build configuration and platform.(string?buildType,string?platform,boolbuild,booldeploy)=project.GetProjectConfiguration(buildConfiguration,buildPlatform);if(buildTypeisnull||platformisnull){Console.WriteLine("Project {0} missing a configuration for {1}|{2}.",projectFilePath,buildConfiguration,buildPlatform);continue;}if(build){Console.WriteLine("Project {0} is set to build as {1}|{2}.",projectFilePath,buildType,platform);}if(deploy){Console.WriteLine("Project {0} is set to deploy as {1}|{2}.",projectFilePath,buildType,platform);}}}
Add a project with an optional solution folder
privatestaticvoidAddProject(SolutionModelsolution,string?solutionFolder,stringprojectFilePath){SolutionFolderModel?parentSolutionFolder=null;if(solutionFolderis not null){parentSolutionFolder=solution.AddFolder(solutionFolder);}// If the project type can be determined from the file extension, the project type name is optional.// If it cannot, a built-in name can be used, such as "Website" for a website project.// If it is not a built-in name, a project type can be added to the solution.// Finally the project type id guid can be used.string?projectTypeName=null;SolutionProjectModelnewProject=solution.AddProject(projectFilePath,projectTypeName,parentSolutionFolder);}