///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
using System.IO;
using System.Reflection;
using JetBrains.Build.Common.Infra;
using Microsoft.Build.Framework;
namespace JetBrains.Build.Common.Tasks
{
///
/// Throws if any of the input file is missing a strong name.
///
public class AssertStrongName : TaskBase
{
#region Attributes
///
/// Specifies the list of the files to check for the strong name.
///
[Required]
public ITaskItem[] InputFiles
{
get
{
return BagGet(AttributeName.InputFiles);
}
set
{
BagSet(AttributeName.InputFiles, value);
}
}
#endregion
#region Overrides
///
/// The method to be overriden in inheriting tasks.
/// Throw an exception in case of an errror.
///
protected override void ExecuteTask()
{
foreach(ITaskItem item in BagGet(AttributeName.InputFiles))
{
var fi = new FileInfo(item.GetMetadata("FullPath"));
if(!fi.Exists)
throw new InvalidOperationException(string.Format("The assembly file “{0}” could not be found.", fi.FullName));
AssemblyName assemblyname = AssemblyName.GetAssemblyName(fi.FullName);
byte[] token = assemblyname.GetPublicKeyToken();
if((token == null) || (token.Length == 0))
throw new InvalidOperationException(string.Format("The assembly “{0}” from file “{1}” is missing a strong name.", assemblyname.FullName, fi.FullName));
}
}
#endregion
}
}