Example #1
0
        /// <summary>See <see cref="Task.Execute"/>.</summary>
        public override bool Execute()
        {
            TaskLoggingHelper log = base.Log;

            ITaskItem[]            regexCompilationInfoFiles = this.RegexCompilationInfoFiles;
            RegexCompilationInfo[] regexCompilationInfos     = new RegexCompilationInfo[regexCompilationInfoFiles.Length];
            for (int i = 0; i < regexCompilationInfoFiles.Length; i++)
            {
                regexCompilationInfos[i] = RegexCompiler.LoadRegexCompilationInfo(log, regexCompilationInfoFiles[i].GetMetadata("FullPath"));
            }

            AssemblyName assemblyName             = new AssemblyName(this.AssemblyName);
            string       relativeAssemblyCodeBase = Path.Combine(this.IntermediateOutputPath, assemblyName.Name + ".dll");

            assemblyName.CodeBase = Path.GetFullPath(relativeAssemblyCodeBase);
            string strongNameKeySource;

            if (!string.IsNullOrEmpty(strongNameKeySource = this.KeyContainer))
            {
                assemblyName.KeyPair = new StrongNameKeyPair(strongNameKeySource);
            }
            else if (!string.IsNullOrEmpty(strongNameKeySource = this.KeyFile))
            {
                using (FileStream fileStream = new FileStream(strongNameKeySource, FileMode.Open, FileAccess.Read, FileShare.Read, 8192, FileOptions.SequentialScan))
                {
                    assemblyName.KeyPair = new StrongNameKeyPair(fileStream);
                }
            }

            log.LogMessage("{0} regex assembly will be created with AssemblyName \"{1}\" and CodeBase \"{2}\".", assemblyName.KeyPair != null ? "Signed" : "Unsigned", assemblyName.FullName, relativeAssemblyCodeBase);

            using (RegexCompilationProxyWrapper regexCompilationProxyWrapper = new RegexCompilationProxyWrapper(this.AlwaysCompileRegexInSeparateDomain))
            {
                regexCompilationProxyWrapper.CompileToAssembly(regexCompilationInfos, assemblyName);
            }

            this._outputAssembly = new TaskItem(relativeAssemblyCodeBase);

            return(!log.HasLoggedErrors);
        }
Example #2
0
		/// <summary>See <see cref="Task.Execute"/>.</summary>
		public override bool Execute()
		{
			TaskLoggingHelper log = base.Log;
			ITaskItem[] regexCompilationInfoFiles = this.RegexCompilationInfoFiles;
			RegexCompilationInfo[] regexCompilationInfos = new RegexCompilationInfo[regexCompilationInfoFiles.Length];
			for (int i = 0; i < regexCompilationInfoFiles.Length; i++)
			{
				regexCompilationInfos[i] = RegexCompiler.LoadRegexCompilationInfo(log, regexCompilationInfoFiles[i].GetMetadata("FullPath"));
			}

			AssemblyName assemblyName = new AssemblyName(this.AssemblyName);
			string relativeAssemblyCodeBase = Path.Combine(this.IntermediateOutputPath, assemblyName.Name + ".dll");
			assemblyName.CodeBase = Path.GetFullPath(relativeAssemblyCodeBase);
			string strongNameKeySource;
			if (!string.IsNullOrEmpty(strongNameKeySource = this.KeyContainer))
			{
				assemblyName.KeyPair = new StrongNameKeyPair(strongNameKeySource);
			}
			else if (!string.IsNullOrEmpty(strongNameKeySource = this.KeyFile))
			{
				using (FileStream fileStream = new FileStream(strongNameKeySource, FileMode.Open, FileAccess.Read, FileShare.Read, 8192, FileOptions.SequentialScan))
				{
					assemblyName.KeyPair = new StrongNameKeyPair(fileStream);
				}
			}

			log.LogMessage("{0} regex assembly will be created with AssemblyName \"{1}\" and CodeBase \"{2}\".", assemblyName.KeyPair != null ? "Signed" : "Unsigned", assemblyName.FullName, relativeAssemblyCodeBase);

			using (RegexCompilationProxyWrapper regexCompilationProxyWrapper = new RegexCompilationProxyWrapper(this.AlwaysCompileRegexInSeparateDomain))
			{
				regexCompilationProxyWrapper.CompileToAssembly(regexCompilationInfos, assemblyName);
			}

			this._outputAssembly = new TaskItem(relativeAssemblyCodeBase);

			return !log.HasLoggedErrors;
		}