Add Conditional Target capabilities to the build scripts
Make Attribute properties immutable PR Feedback, bugfixes PR Feedback
This commit is contained in:
parent
adc6aa7eff
commit
6d8b622451
16 changed files with 415 additions and 116 deletions
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build.Framework
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public class BuildPlatformsAttribute : TargetConditionAttribute
|
||||
{
|
||||
private IEnumerable<BuildPlatform> _buildPlatforms;
|
||||
|
||||
public BuildPlatformsAttribute(params BuildPlatform[] platforms)
|
||||
{
|
||||
if (platforms == null)
|
||||
{
|
||||
throw new ArgumentNullException("platforms");
|
||||
}
|
||||
|
||||
_buildPlatforms = platforms;
|
||||
}
|
||||
|
||||
public override bool EvaluateCondition()
|
||||
{
|
||||
var currentPlatform = CurrentPlatform.Current;
|
||||
|
||||
if (currentPlatform == default(BuildPlatform))
|
||||
{
|
||||
throw new Exception("Unrecognized Platform.");
|
||||
}
|
||||
|
||||
foreach (var platform in _buildPlatforms)
|
||||
{
|
||||
if (platform == currentPlatform)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue