/src/AddIns/Misc/PackageManagement/Project/Src/ProjectTargetFramework.cs

https://github.com/ajadex/SharpDevelop · C# · 79 lines · 51 code · 11 blank · 17 comment · 1 complexity · e2efbcf243c4ebf5fcba4a33959d67f8 MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Runtime.Versioning;
  20. using ICSharpCode.SharpDevelop.Project;
  21. namespace ICSharpCode.PackageManagement
  22. {
  23. public class ProjectTargetFramework
  24. {
  25. MSBuildBasedProject project;
  26. FrameworkName targetFramework;
  27. public ProjectTargetFramework(MSBuildBasedProject project)
  28. {
  29. this.project = project;
  30. GetTargetFramework();
  31. }
  32. void GetTargetFramework()
  33. {
  34. string identifier = GetTargetFrameworkIdentifier();
  35. string version = GetTargetFrameworkVersion();
  36. string profile = GetTargetFrameworkProfile();
  37. GetTargetFramework(identifier, version, profile);
  38. }
  39. void GetTargetFramework(string identifier, string version, string profile)
  40. {
  41. string name = String.Format("{0}, Version={1}, Profile={2}", identifier, version, profile);
  42. targetFramework = new FrameworkName(name);
  43. }
  44. string GetTargetFrameworkIdentifier()
  45. {
  46. return GetEvaluatedPropertyOrDefault("TargetFrameworkIdentifier", ".NETFramework");
  47. }
  48. string GetTargetFrameworkVersion()
  49. {
  50. return project.GetEvaluatedProperty("TargetFrameworkVersion");
  51. }
  52. string GetTargetFrameworkProfile()
  53. {
  54. return GetEvaluatedPropertyOrDefault("TargetFrameworkProfile", String.Empty);
  55. }
  56. string GetEvaluatedPropertyOrDefault(string propertyName, string defaultPropertyValue)
  57. {
  58. string propertyValue = project.GetEvaluatedProperty(propertyName);
  59. if (String.IsNullOrEmpty(propertyValue)) {
  60. return defaultPropertyValue;
  61. }
  62. return propertyValue;
  63. }
  64. public FrameworkName TargetFrameworkName {
  65. get { return targetFramework; }
  66. }
  67. }
  68. }