OutputAttribute OutputAttribute OutputAttribute OutputAttribute Class


タスクからデータを出力するタスク プロパティを識別するためにタスクの作成者が使用するメタデータ属性を定義します。Defines the metadata attribute that task authors use to identify task properties that output data from the task.

public ref class OutputAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
public sealed class OutputAttribute : Attribute
type OutputAttribute = class
    inherit Attribute
Public NotInheritable Class OutputAttribute
Inherits Attribute

次の例は、1つ以上のディレクトリを作成するタスクのコードを示しています。The following example shows the code for a task that creates one or more directories.

using System;
using System.IO;
using System.Security;
using System.Collections;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.Build.Tasks
	 * Class: MakeDir
	 * An MSBuild task that creates one or more directories.
	public class MakeDir : Task
	    // The Required attribute indicates the following to MSBuild:
	    //	     - if the parameter is a scalar type, and it is not supplied, fail the build immediately
	    //	     - if the parameter is an array type, and it is not supplied, pass in an empty array
	    // In this case the parameter is an array type, so if a project fails to pass in a value for the 
            // Directories parameter, the task will get invoked, but this implementation will do nothing,
            // because the array will be empty.
            // Directories to create.
		public ITaskItem[] Directories
				return directories;

				directories = value;

		// The Output attribute indicates to MSBuild that the value of this property can be gathered after the
		// task has returned from Execute(), if the project has an <Output> tag under this task's element for 
		// this property.
		// A project may need the subset of the inputs that were actually created, so make that available here.
		public ITaskItem[] DirectoriesCreated
				return directoriesCreated;

		private ITaskItem[] directories;
		private ITaskItem[] directoriesCreated;

		/// <summary>
		/// Execute is part of the Microsoft.Build.Framework.ITask interface.
		/// When it's called, any input parameters have already been set on the task's properties.
		/// It returns true or false to indicate success or failure.
		/// </summary>
		public override bool Execute()
			ArrayList items = new ArrayList();
			foreach (ITaskItem directory in Directories)
				// ItemSpec holds the filename or path of an Item
				if (directory.ItemSpec.Length > 0)
						// Only log a message if we actually need to create the folder
						if (!Directory.Exists(directory.ItemSpec))
							Log.LogMessage(MessageImportance.Normal, "Creating directory " + directory.ItemSpec);

						// Add to the list of created directories
					// If a directory fails to get created, log an error, but proceed with the remaining 
					// directories.
					catch (Exception ex)
						if (ex is IOException
							|| ex is UnauthorizedAccessException
							|| ex is PathTooLongException
							|| ex is DirectoryNotFoundException
							|| ex is SecurityException)
							Log.LogError("Error trying to create directory " + directory.ItemSpec + ". " + ex.Message);

			// Populate the "DirectoriesCreated" output items.
			directoriesCreated = (ITaskItem[])items.ToArray(typeof(ITaskItem));

			// Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged 
			// from a task's constructor or property setter. As long as this task is written to always log an error
			// when it fails, we can reliably return HasLoggedErrors.
			return !Log.HasLoggedErrors;


エンジンMSBuildMSBuildは、この属性でマークされたタスクプロパティのみがタスクからデータを出力できるようにします。The MSBuildMSBuild engine will only allow task properties marked with this attribute to output data from a task. プロジェクトの作成者は、プロジェクトファイルの要素で、 Outputこの属性でマークされたプロパティのみを使用できます。Project authors can only use properties marked with this attribute in the Output element of a project file. その他のすべてのタスクプロパティは、タスクへの入力として扱われます。All other task properties are treated as inputs to a task.

属性の使用方法の詳細については、「属性を使用したメタデータの拡張」を参照してください。For more information about using attributes, see Extending Metadata Using Attributes.


OutputAttribute() OutputAttribute() OutputAttribute() OutputAttribute()

OutputAttribute クラスの新しいインスタンスを初期化します。Initializes a new instance of the OutputAttribute class.


Equals(Object) Equals(Object) Equals(Object) Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

このインスタンスのハッシュ コードを返します。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)


_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)


TypeId TypeId TypeId TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)