コード例 #1
0
ファイル: MsiTask.cs プロジェクト: riha/BtsMsiTask
        /// <summary>
        /// MSBuild entry point for generating a MSI file based on a BizTalk Server project.
        /// </summary>
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.High, "Executing MsiTask version {0}", Assembly.GetExecutingAssembly().GetName().Version);

            if (!Directory.Exists(DestinationPath))
                Directory.CreateDirectory((DestinationPath));

            if (!string.IsNullOrEmpty(FileName) && Path.GetExtension(FileName) != ".msi")
            {
                Log.LogError("MSI file name has to end with file suffix '.MSI'");
                return false;
            }

            if ((BtsAssemblies == null || !BtsAssemblies.Any()) && (Resources == null || !Resources.Any()))
            {
                throw new ArgumentException("No BizTalk Assemblies and no assembly resources found in build project input");
            }

            // TODO: Add all checking of parameters to separate classes
            // TODO: Check all required in parameters and set possible defaults
            // TODO: Check that it's BT 2013 server from registry
            // TODO: Add better and cleaner error messages to msbuild output
            // TODO: Is it possible to check if assembly is signed or not?

            var resources = new List<Resource>();

            if (BtsAssemblies != null && BtsAssemblies.Any())
                resources.AddRange(BtsAssemblies.Select(r => new Resource(r.GetMetadata("Fullpath"), ResourceType.BtsResource)));

            if (Resources != null && Resources.Any())
                resources.AddRange(Resources.Select(r => new Resource(r.GetMetadata("Fullpath"), ResourceType.Resource)));

            if (!string.IsNullOrEmpty(SourceLocation))
                resources.ForEach(r => r.SourceLocation = SourceLocation);

            var references = new List<string>();
            if (ReferenceApplications != null)
                references.AddRange(ReferenceApplications.Select(reference => reference.ItemSpec));

            var btsApplication = new BtsApplication(ApplicationName)
            {
                Description = ApplicationDescription,
                ReferencedApplications = references.ToArray()
            };

            var msiWriter = new BtsMsiLib.MsiWriter();
            var msiFile = msiWriter.Write(btsApplication, resources.ToArray());

            var destinationFilePath = Path.Combine(DestinationPath, FileHelper.GetMsiFileName(ApplicationName, FileName));

            using (var destinationFile = File.Create(destinationFilePath)) { msiFile.CopyTo(destinationFile); }

            Log.LogMessage(MessageImportance.Normal, "MSI was successfully generated at {0}", destinationFilePath);

            return true;
        }
コード例 #2
0
ファイル: MsiTask.cs プロジェクト: riha/BtsMsiTask
        /// <summary>
        /// MSBuild entry point for generating a MSI file based on a BizTalk Server project.
        /// </summary>
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.High, "Executing MsiTask version {0}", Assembly.GetExecutingAssembly().GetName().Version);

            if (!Directory.Exists(DestinationPath))
            {
                Directory.CreateDirectory((DestinationPath));
            }

            if (!string.IsNullOrEmpty(FileName) && Path.GetExtension(FileName) != ".msi")
            {
                Log.LogError("MSI file name has to end with file suffix '.MSI'");
                return(false);
            }

            if ((BtsAssemblies == null || !BtsAssemblies.Any()) && (Resources == null || !Resources.Any()))
            {
                throw new ArgumentException("No BizTalk Assemblies and no assembly resources found in build project input");
            }

            // TODO: Add all checking of parameters to separate classes
            // TODO: Check all required in parameters and set possible defaults
            // TODO: Check that it's BT 2013 server from registry
            // TODO: Add better and cleaner error messages to msbuild output
            // TODO: Is it possible to check if assembly is signed or not?

            var resources = new List <Resource>();

            if (BtsAssemblies != null && BtsAssemblies.Any())
            {
                resources.AddRange(BtsAssemblies.Select(r => new Resource(r.GetMetadata("Fullpath"), ResourceType.BtsResource)));
            }

            if (Resources != null && Resources.Any())
            {
                resources.AddRange(Resources.Select(r => new Resource(r.GetMetadata("Fullpath"), ResourceType.Resource)));
            }

            if (!string.IsNullOrEmpty(SourceLocation))
            {
                resources.ForEach(r => r.SourceLocation = SourceLocation);
            }

            var references = new List <string>();

            if (ReferenceApplications != null)
            {
                references.AddRange(ReferenceApplications.Select(reference => reference.ItemSpec));
            }

            var btsApplication = new BtsApplication(ApplicationName)
            {
                Description            = ApplicationDescription,
                ReferencedApplications = references.ToArray()
            };

            var msiWriter = new BtsMsiLib.MsiWriter();
            var msiFile   = msiWriter.Write(btsApplication, resources.ToArray());

            var destinationFilePath = Path.Combine(DestinationPath, FileHelper.GetMsiFileName(ApplicationName, FileName));

            using (var destinationFile = File.Create(destinationFilePath)) { msiFile.CopyTo(destinationFile); }

            Log.LogMessage(MessageImportance.Normal, "MSI was successfully generated at {0}", destinationFilePath);

            return(true);
        }