Microsoft.Build.Tasks.GenerateResource.Execute C# (CSharp) Method

Execute() public method

public Execute ( ) : bool
return bool
		public override bool Execute ()
		{
			if (sources.Length == 0)
				return true;

			bool result = true;
			List  <ITaskItem> temporaryFilesWritten = new List <ITaskItem> ();
			if (outputResources == null) {
				foreach (ITaskItem source in sources) {
					string sourceFile = source.ItemSpec;
					string outputFile = Path.ChangeExtension (sourceFile, "resources");

					if (IsResgenRequired (sourceFile, outputFile))
						result &= CompileResourceFile (sourceFile, outputFile);

					ITaskItem newItem = new TaskItem (source);
					source.ItemSpec = outputFile;

					temporaryFilesWritten.Add (newItem);
				}
			} else {
				if (sources.Length != outputResources.Length) {
					Log.LogError ("Sources count is different than OutputResources count.");
					return false;
				}

				for (int i = 0; i < sources.Length; i ++) {
					if (String.IsNullOrEmpty (outputResources [i].ItemSpec)) {
						Log.LogError ("Filename of output can not be empty.");
						result = false;
						continue;
					}

					if (IsResgenRequired (sources [i].ItemSpec, outputResources [i].ItemSpec))
						result &= CompileResourceFile (sources [i].ItemSpec, outputResources [i].ItemSpec);
					temporaryFilesWritten.Add (outputResources [i]);
				}
			}
			
			filesWritten = temporaryFilesWritten.ToArray ();

			return result;
		}
		

Usage Example

Example #1
0
        /// <summary>
        /// ExecuteTask performs the task Execute method and asserts basic success criteria
        /// </summary>
        public static void ExecuteTask(GenerateResource t)
        {
            bool success = t.Execute();
            Assert.True(success);

            if (t.OutputResources != null && t.OutputResources[0] != null)
            {
                DateTime resourcesLastModified = File.GetLastWriteTime(t.OutputResources[0].ItemSpec);
                if (t.Sources[0] != null)
                    Assert.True(resourcesLastModified >= File.GetLastWriteTime(t.Sources[0].ItemSpec));
            }
        }