OLD | NEW |
| (Empty) |
1 /*************************************************************************** | |
2 | |
3 Copyright (c) Microsoft Corporation. All rights reserved. | |
4 This code is licensed under the Visual Studio SDK license terms. | |
5 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF | |
6 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY | |
7 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR | |
8 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. | |
9 | |
10 ***************************************************************************/ | |
11 | |
12 using System; | |
13 | |
14 namespace Microsoft.VisualStudio.Shell | |
15 { | |
16 /// <summary> | |
17 /// This attribute register a custom .targets files to the list of the | |
18 /// targets known and trusted by MSBuild. | |
19 /// | |
20 /// The registry entries created are: | |
21 /// [%RegistryRoot%\MSBuild\SafeImports] | |
22 /// "TargetsLabel"="PathToTheTargetsFile" | |
23 /// | |
24 /// </summary> | |
25 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = tr
ue)] | |
26 public sealed class ProvideMSBuildTargetsAttribute : RegistrationAttribute | |
27 { | |
28 private const string MSBuildSafeImportsPath = @"MSBuild\SafeImports"; | |
29 private string targetsLabel; | |
30 private string targetsPath; | |
31 | |
32 /// <summary> | |
33 /// Creates a new ProvideMSBuildTargets attribute to register a targets
file | |
34 /// to the list of the MSBuild safe imports. | |
35 /// </summary> | |
36 /// <param name="targetsLabel">Label to identify the targets.</param> | |
37 /// <param name="targetsPath">Full path to the targets file.</param> | |
38 public ProvideMSBuildTargetsAttribute(string targetsLabel, string target
sPath) | |
39 { | |
40 if (string.IsNullOrEmpty(targetsLabel)) | |
41 { | |
42 throw new ArgumentNullException("targetsLabel"); | |
43 } | |
44 if (string.IsNullOrEmpty(targetsPath)) | |
45 { | |
46 throw new ArgumentNullException("targetsPath"); | |
47 } | |
48 this.targetsLabel = targetsLabel; | |
49 this.targetsPath = targetsPath; | |
50 } | |
51 | |
52 /// <summary> | |
53 /// Called to register this attribute with the given context. The c
ontext | |
54 /// contains the location where the registration inforomation should
be placed. | |
55 /// It also contains other information such as the type being regist
ered and path information. | |
56 /// </summary> | |
57 public override void Register(RegistrationContext context) | |
58 { | |
59 if (null == context) { | |
60 new ArgumentNullException("context"); | |
61 } | |
62 using (Key safeImportsKey = context.CreateKey(MSBuildSafeImportsPath
)) | |
63 { | |
64 safeImportsKey.SetValue(targetsLabel, targetsPath); | |
65 } | |
66 | |
67 } | |
68 | |
69 /// <summary> | |
70 /// Unregister this file extension. | |
71 /// </summary> | |
72 /// <param name="context"></param> | |
73 public override void Unregister(RegistrationContext context) | |
74 { | |
75 if (null != context) | |
76 { | |
77 context.RemoveValue(MSBuildSafeImportsPath, targetsLabel); | |
78 } | |
79 } | |
80 } | |
81 } | |
OLD | NEW |