summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.BuildTasks/ReSignDelaySignedAssemblies.cs
blob: 0d9dba8f3db4f6176c69bee5381bc35233e0d5e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//-----------------------------------------------------------------------
// <copyright file="ReSignDelaySignedAssemblies.cs" company="Outercurve Foundation">
//     Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.BuildTasks {
	using System;
	using Microsoft.Build.Framework;
	using Microsoft.Build.Utilities;

	public class ReSignDelaySignedAssemblies : SnToolTask {
		/// <summary>
		/// Gets or sets the key file to use for signing.
		/// </summary>
		public ITaskItem KeyFile { get; set; }

		/// <summary>
		/// Gets or sets the key container.
		/// </summary>
		public ITaskItem KeyContainer { get; set; }

		/// <summary>
		/// Gets or sets the assemblies to re-sign.
		/// </summary>
		public ITaskItem[] Assemblies { get; set; }

		/// <summary>
		/// Generates the command line commands.
		/// </summary>
		protected override string GenerateCommandLineCommands() {
			////if (this.Assemblies.Length != 1) {
			////    throw new NotSupportedException("Exactly 1 assembly for signing is supported.");
			////}
			var args = new CommandLineBuilder();
			args.AppendSwitch("-q");

			if (this.KeyFile != null) {
				args.AppendSwitch("-R");
			} else if (this.KeyContainer != null) {
				args.AppendSwitch("-Rc");
			} else {
				throw new InvalidOperationException("Either KeyFile or KeyContainer must be set.");
			}

			args.AppendFileNameIfNotNull(this.Assemblies[0]);
			if (this.KeyFile != null) {
				args.AppendFileNameIfNotNull(this.KeyFile);
			} else {
				args.AppendFileNameIfNotNull(this.KeyContainer);
			}

			return args.ToString();
		}
	}
}