public async Task <ImmutableArray <ProjectFileInfo> > GetProjectFileInfosAsync(CancellationToken cancellationToken) { var targetFrameworkValue = _loadedProject.GetPropertyValue(PropertyNames.TargetFramework); var targetFrameworksValue = _loadedProject.GetPropertyValue(PropertyNames.TargetFrameworks); if (string.IsNullOrEmpty(targetFrameworkValue) && !string.IsNullOrEmpty(targetFrameworksValue)) { // This project has a <TargetFrameworks> property, but does not specify a <TargetFramework>. // In this case, we need to iterate through the <TargetFrameworks>, set <TargetFramework> with // each value, and build the project. var targetFrameworks = targetFrameworksValue.Split(';'); var results = ImmutableArray.CreateBuilder <ProjectFileInfo>(targetFrameworks.Length); if (!_loadedProject.GlobalProperties.TryGetValue(PropertyNames.TargetFramework, out var initialGlobalTargetFrameworkValue)) { initialGlobalTargetFrameworkValue = null; } foreach (var targetFramework in targetFrameworks) { _loadedProject.SetGlobalProperty(PropertyNames.TargetFramework, targetFramework); _loadedProject.ReevaluateIfNecessary(); var projectFileInfo = await BuildProjectFileInfoAsync(cancellationToken).ConfigureAwait(false); results.Add(projectFileInfo); } if (initialGlobalTargetFrameworkValue is null) { _loadedProject.RemoveGlobalProperty(PropertyNames.TargetFramework); } else { _loadedProject.SetGlobalProperty(PropertyNames.TargetFramework, initialGlobalTargetFrameworkValue); } _loadedProject.ReevaluateIfNecessary(); return(results.ToImmutable()); } else { var projectFileInfo = await BuildProjectFileInfoAsync(cancellationToken).ConfigureAwait(false); return(ImmutableArray.Create(projectFileInfo)); } }
private static async Task <TranspilerStatus> BuildProject(Project project) { return(await System.Threading.Tasks.Task.Run(() => { try { if (!_buildProjects.ContainsKey(project.UniqueName)) { var root = Microsoft.Build.Construction.ProjectRootElement.Open(project.FullName); var proj = new MSbuildProject(root); proj.SetGlobalProperty("BuildingProject", "true"); _buildProjects[project.UniqueName] = proj; } bool success = _buildProjects[project.UniqueName].Build(new[] { "FindConfigFiles", "CompileTypeScriptWithTsConfig" }); return success ? TranspilerStatus.Ok : TranspilerStatus.BuildFailed; } catch (Exception ex) { Logger.Log(ex); return TranspilerStatus.Exception; } })); }
public MsBuildConditionContext(Microsoft.Build.Evaluation.Project msBuildProject, Dictionary <string, string> propertyValues) { _msBuildProject = msBuildProject; foreach (var propertyValue in propertyValues) { _setPropertyNames.Add(propertyValue.Key); _msBuildProject.SetGlobalProperty(propertyValue.Key, propertyValue.Value); } _msBuildProject.ReevaluateIfNecessary(); }
private static void SetTargetFrameworkIfNeeded(MSB.Evaluation.Project evaluatedProject) { var targetFramework = evaluatedProject.GetPropertyValue(PropertyNames.TargetFramework); var targetFrameworks = PropertyConverter.SplitList(evaluatedProject.GetPropertyValue(PropertyNames.TargetFrameworks), ';'); // If the project supports multiple target frameworks and specific framework isn't // selected, we must pick one before execution. Otherwise, the ResolveReferences // target might not be available to us. if (string.IsNullOrWhiteSpace(targetFramework) && targetFrameworks.Length > 0) { // For now, we'll just pick the first target framework. Eventually, we'll need to // do better and potentially allow OmniSharp hosts to select a target framework. targetFramework = targetFrameworks[0]; evaluatedProject.SetGlobalProperty(PropertyNames.TargetFramework, targetFramework); evaluatedProject.ReevaluateIfNecessary(); } }
public async Task Basic_SetIntermediateOutputPathProperty() { var intermediateOutputPath = @"foo\bar\"; nuproj.CreateMockContentFiles(); nuproj.SetGlobalProperty("IntermediateOutputPath", intermediateOutputPath); var result = await MSBuild.ExecuteAsync(nuproj.CreateProjectInstance(), this.logger); result.AssertSuccessfulBuild(); var expectedNuSpecFileName = string.Format(CultureInfo.InvariantCulture, "{0}.nuspec", nuproj.GetPropertyValue("Id")); var nuprojFileName = Path.GetFileNameWithoutExtension(nuproj.FullPath); var expectedNuSpecPath = Path.Combine(intermediateOutputPath, expectedNuSpecFileName); var actualNuSpecPath = await nuproj.GetNuSpecPathAsync(); Assert.Equal(expectedNuSpecPath, actualNuSpecPath, StringComparer.InvariantCultureIgnoreCase); }
public void TestAddPropertyGroupForSolutionConfigurationBuildProjectInSolutionNotSet() { string solutionFileContents = @" Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project('{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}') = 'ClassLibrary1', 'ClassLibrary1\ClassLibrary1.csproj', '{6185CC21-BE89-448A-B3C0-D1C27112E595}' EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Mixed Platforms = Debug|Mixed Platforms Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6185CC21-BE89-448A-B3C0-D1C27112E595}.Debug|Mixed Platforms.ActiveCfg = CSConfig1|Any CPU EndGlobalSection EndGlobal "; SolutionFile solution = SolutionFile_Tests.ParseSolutionHelper(solutionFileContents); ProjectRootElement projectXml = ProjectRootElement.Create(); foreach (SolutionConfigurationInSolution solutionConfiguration in solution.SolutionConfigurations) { SolutionProjectGenerator.AddPropertyGroupForSolutionConfiguration(projectXml, solution, solutionConfiguration); } Project msbuildProject = new Project(projectXml); // Both projects configurations should be present for solution configuration "Debug|Mixed Platforms" msbuildProject.SetGlobalProperty("Configuration", "Debug"); msbuildProject.SetGlobalProperty("Platform", "Mixed Platforms"); msbuildProject.ReevaluateIfNecessary(); string solutionConfigurationContents = msbuildProject.GetPropertyValue("CurrentSolutionConfigurationContents"); Assert.IsTrue(solutionConfigurationContents.Contains(@"BuildProjectInSolution=""" + bool.FalseString + @"""")); }
public void TestAddPropertyGroupForSolutionConfiguration() { string solutionFileContents = @" Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project('{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}') = 'ClassLibrary1', 'ClassLibrary1\ClassLibrary1.csproj', '{6185CC21-BE89-448A-B3C0-D1C27112E595}' EndProject Project('{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}') = 'MainApp', 'MainApp\MainApp.vcxproj', '{A6F99D27-47B9-4EA4-BFC9-25157CBDC281}' EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Mixed Platforms = Debug|Mixed Platforms Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6185CC21-BE89-448A-B3C0-D1C27112E595}.Debug|Mixed Platforms.ActiveCfg = CSConfig1|Any CPU {6185CC21-BE89-448A-B3C0-D1C27112E595}.Debug|Mixed Platforms.Build.0 = CSConfig1|Any CPU {6185CC21-BE89-448A-B3C0-D1C27112E595}.Release|Any CPU.ActiveCfg = CSConfig2|Any CPU {A6F99D27-47B9-4EA4-BFC9-25157CBDC281}.Debug|Mixed Platforms.ActiveCfg = VCConfig1|Win32 {A6F99D27-47B9-4EA4-BFC9-25157CBDC281}.Debug|Mixed Platforms.Build.0 = VCConfig1|Win32 EndGlobalSection EndGlobal "; SolutionFile solution = SolutionFile_Tests.ParseSolutionHelper(solutionFileContents); ProjectRootElement projectXml = ProjectRootElement.Create(); foreach (SolutionConfigurationInSolution solutionConfiguration in solution.SolutionConfigurations) { SolutionProjectGenerator.AddPropertyGroupForSolutionConfiguration(projectXml, solution, solutionConfiguration); } Project msbuildProject = new Project(projectXml); // Both projects configurations should be present for solution configuration "Debug|Mixed Platforms" msbuildProject.SetGlobalProperty("Configuration", "Debug"); msbuildProject.SetGlobalProperty("Platform", "Mixed Platforms"); msbuildProject.ReevaluateIfNecessary(); string solutionConfigurationContents = msbuildProject.GetPropertyValue("CurrentSolutionConfigurationContents"); string tempProjectPath = Path.Combine(Path.GetTempPath(), "ClassLibrary1\\ClassLibrary1.csproj"); Assert.IsTrue(solutionConfigurationContents.Contains("{6185CC21-BE89-448A-B3C0-D1C27112E595}")); tempProjectPath = Path.GetFullPath(tempProjectPath); Assert.IsTrue(solutionConfigurationContents.IndexOf(tempProjectPath, StringComparison.OrdinalIgnoreCase) > 0); Assert.IsTrue(solutionConfigurationContents.Contains("CSConfig1|AnyCPU")); tempProjectPath = Path.Combine(Path.GetTempPath(), "MainApp\\MainApp.vcxproj"); tempProjectPath = Path.GetFullPath(tempProjectPath); Assert.IsTrue(solutionConfigurationContents.Contains("{A6F99D27-47B9-4EA4-BFC9-25157CBDC281}")); Assert.IsTrue(solutionConfigurationContents.IndexOf(tempProjectPath, StringComparison.OrdinalIgnoreCase) > 0); Assert.IsTrue(solutionConfigurationContents.Contains("VCConfig1|Win32")); // Only the C# project should be present for solution configuration "Release|Any CPU", since the VC project // is missing msbuildProject.SetGlobalProperty("Configuration", "Release"); msbuildProject.SetGlobalProperty("Platform", "Any CPU"); msbuildProject.ReevaluateIfNecessary(); solutionConfigurationContents = msbuildProject.GetPropertyValue("CurrentSolutionConfigurationContents"); Assert.IsTrue(solutionConfigurationContents.Contains("{6185CC21-BE89-448A-B3C0-D1C27112E595}")); Assert.IsTrue(solutionConfigurationContents.Contains("CSConfig2|AnyCPU")); Assert.IsFalse(solutionConfigurationContents.Contains("{A6F99D27-47B9-4EA4-BFC9-25157CBDC281}")); }
public void SolutionConfigurationWithDependencies() { string solutionFileContents = @" Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 11 Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `A`, `Project1\A.csproj`, `{786E302A-96CE-43DC-B640-D6B6CC9BF6C0}` EndProject Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `B`, `Project2\B.csproj`, `{881C1674-4ECA-451D-85B6-D7C59B7F16FA}` ProjectSection(ProjectDependencies) = postProject {4A727FF8-65F2-401E-95AD-7C8BBFBE3167} = {4A727FF8-65F2-401E-95AD-7C8BBFBE3167} EndProjectSection EndProject Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `C`, `Project3\C.csproj`, `{4A727FF8-65F2-401E-95AD-7C8BBFBE3167}` EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = preSolution {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Debug|x64.ActiveCfg = Debug|Any CPU {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Debug|x64.Build.0 = Debug|Any CPU {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Release|Any CPU.ActiveCfg = Release|Any CPU {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Release|Any CPU.Build.0 = Release|Any CPU {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Release|x64.ActiveCfg = Release|Any CPU {4A727FF8-65F2-401E-95AD-7C8BBFBE3167}.Release|x64.Build.0 = Release|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Debug|x64.ActiveCfg = Debug|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Debug|x64.Build.0 = Debug|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Release|Any CPU.Build.0 = Release|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Release|x64.ActiveCfg = Release|Any CPU {786E302A-96CE-43DC-B640-D6B6CC9BF6C0}.Release|x64.Build.0 = Release|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Debug|Any CPU.Build.0 = Debug|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Debug|x64.ActiveCfg = Debug|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Debug|x64.Build.0 = Debug|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Release|Any CPU.ActiveCfg = Release|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Release|Any CPU.Build.0 = Release|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Release|x64.ActiveCfg = Release|Any CPU {881C1674-4ECA-451D-85B6-D7C59B7F16FA}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ".Replace("`", "\""); SolutionFile solution = SolutionFile_Tests.ParseSolutionHelper(solutionFileContents); ProjectRootElement projectXml = ProjectRootElement.Create(); foreach (SolutionConfigurationInSolution solutionConfiguration in solution.SolutionConfigurations) { SolutionProjectGenerator.AddPropertyGroupForSolutionConfiguration(projectXml, solution, solutionConfiguration); } Project msbuildProject = new Project(projectXml); // Both projects configurations should be present for solution configuration "Debug|Mixed Platforms" msbuildProject.SetGlobalProperty("Configuration", "Debug"); msbuildProject.SetGlobalProperty("Platform", "Any CPU"); msbuildProject.ReevaluateIfNecessary(); string solutionConfigurationContents = msbuildProject.GetPropertyValue("CurrentSolutionConfigurationContents"); // Only the specified solution configuration is represented in THE BLOB: nothing for x64 in this case string expected = @"<SolutionConfiguration> <ProjectConfiguration Project=`{786E302A-96CE-43DC-B640-D6B6CC9BF6C0}` AbsolutePath=`##temp##Project1\A.csproj` BuildProjectInSolution=`True`>Debug|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project=`{881C1674-4ECA-451D-85B6-D7C59B7F16FA}` AbsolutePath=`##temp##Project2\B.csproj` BuildProjectInSolution=`True`>Debug|AnyCPU<ProjectDependency Project=`{4A727FF8-65F2-401E-95AD-7C8BBFBE3167}` /></ProjectConfiguration> <ProjectConfiguration Project=`{4A727FF8-65F2-401E-95AD-7C8BBFBE3167}` AbsolutePath=`##temp##Project3\C.csproj` BuildProjectInSolution=`True`>Debug|AnyCPU</ProjectConfiguration> </SolutionConfiguration>".Replace("`", "\"").Replace("##temp##", Path.GetTempPath()); Helpers.VerifyAssertLineByLine(expected, solutionConfigurationContents); }