Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 14
Samples
Richard Stanton edited this page Aug 9, 2024
·
5 revisions
These are some basic samples using the model and serializers.
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;}}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);}}}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);}