/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Apache License, Version 2.0, please send an email to
* vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Apache License, Version 2.0.
*
* You must not remove this notice, or any other, from this software.
*
* ***************************************************************************/
using Microsoft.VisualStudio;
using System;
namespace Microsoft.VisualStudio.Project {
///
/// Enables the Any CPU Platform form name for Dynamic Projects.
/// Hooks language specific project config.
///
public class CommonConfigProvider : ConfigProvider
{
private CommonProjectNode _project;
public CommonConfigProvider(CommonProjectNode project)
: base(project) {
_project = project;
}
#region overridden methods
///
/// Returns one or more platform names.
///
/// Specifies the requested number of platform names. If this number is unknown, celt can be zero.
/// On input, an allocated array to hold the number of platform names specified by celt. This parameter can also be a null reference if the celt parameter is zero. On output, names contains platform names.
/// The actual number of platform names returned.
/// If the method succeeds, it returns S_OK. If it fails, it returns an error code.
public override int GetPlatformNames(uint celt, string[] names, uint[] actual)
{
string[] platforms = this.GetPlatformsFromProject();
return GetPlatforms(celt, names, actual, platforms);
}
///
/// Returns the set of platforms that are installed on the user's machine.
///
/// Specifies the requested number of supported platform names. If this number is unknown, celt can be zero.
/// On input, an allocated array to hold the number of names specified by celt. This parameter can also be a null reference (Nothing in Visual Basic)if the celt parameter is zero. On output, names contains the names of supported platforms
/// The actual number of platform names returned.
/// If the method succeeds, it returns S_OK. If it fails, it returns an error code.
public override int GetSupportedPlatformNames(uint celt, string[] names, uint[] actual)
{
string[] platforms = this.GetSupportedPlatformsFromProject();
return GetPlatforms(celt, names, actual, platforms);
}
protected override Config CreateProjectConfiguration(string configName, string platformName) {
return _project.MakeConfiguration(configName, platformName);
}
#endregion
///
/// Gets all the platforms defined in the project
///
/// An array of platform names.
private string[] GetPlatformsFromProject()
{
string[] platforms = GetPropertiesConditionedOn(ProjectFileConstants.Platform);
if (platforms == null || platforms.Length == 0)
{
return new string[] { x86Platform, AnyCPUPlatform };
}
for (int i = 0; i < platforms.Length; i++)
{
platforms[i] = ConvertPlatformToVsProject(platforms[i]);
}
return platforms;
}
///
/// Return the supported platform names.
///
/// An array of supported platform names.
private string[] GetSupportedPlatformsFromProject()
{
string platforms = this.ProjectMgr.BuildProject.GetPropertyValue(ProjectFileConstants.AvailablePlatforms);
if (platforms == null)
{
return new string[] { };
}
if (platforms.Contains(","))
{
return platforms.Split(',');
}
return new string[] { platforms };
}
///
/// Helper function to convert AnyCPU to Any CPU.
///
/// The oldname.
/// The new name.
private static string ConvertPlatformToVsProject(string oldPlatformName)
{
if (String.Compare(oldPlatformName, ProjectFileValues.AnyCPU, StringComparison.OrdinalIgnoreCase) == 0)
{
return AnyCPUPlatform;
}
return oldPlatformName;
}
}
}