コード例 #1
0
        public ProjectEx(
            Microsoft.Build.Framework.ITaskItem projectItem,
            Version version,
            string origProjectPath
            )
        {
            this.m_xmlPath = projectItem.ItemSpec;
            this.version   = version;
            m_origProjPath = origProjectPath;

            string deployMetadataValue = projectItem.GetMetadata("Deploy");

            if (deployMetadataValue == "true")
            {
                this.Deploy = true;
            }

            System.Text.RegularExpressions.Regex regex =
                new System.Text.RegularExpressions.Regex(" xmlns=\"http://{0,1}[a-zA-Z0-9/.]*\"+");

            string extraFilesBody = regex.Replace(projectItem.GetMetadata("ExtraFiles"), "");

            string extraFilesXml = string.Format("{0}{1}{2}",
                                                 "<ExtraFiles>",
                                                 extraFilesBody,
                                                 "</ExtraFiles>");

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(extraFilesXml);

            foreach (System.Xml.XmlNode extraFileNode in doc.SelectNodes("ExtraFiles/File"))
            {
                this.AddExtraFile(extraFileNode.Attributes["Name"].Value);
            }
        }
コード例 #2
0
ファイル: ProjectFile.cs プロジェクト: singhsarab/roslyn
        protected static string GetDocumentLogicalPath(MSB.Framework.ITaskItem documentItem, string projectDirectory)
        {
            var link = documentItem.GetMetadata("Link");

            if (!string.IsNullOrEmpty(link))
            {
                // if a specific link is specified in the project file then use it to form the logical path.
                return(link);
            }
            else
            {
                var result = documentItem.ItemSpec;
                if (Path.IsPathRooted(result))
                {
                    // If we have an absolute path, there are two possibilities:
                    result = Path.GetFullPath(result);

                    // If the document is within the current project directory (or subdirectory), then the logical path is the relative path
                    // from the project's directory.
                    if (result.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase))
                    {
                        result = result.Substring(projectDirectory.Length);
                    }
                    else
                    {
                        // if the document lies outside the project's directory (or subdirectory) then place it logically at the root of the project.
                        // if more than one document ends up with the same logical name then so be it (the workspace will survive.)
                        return(Path.GetFileName(result));
                    }
                }

                return(result);
            }
        }
コード例 #3
0
        static public void AddDeclareParameterToCommandArgument(System.Collections.Generic.List <string> arguments,
                                                                Framework.ITaskItem item,
                                                                string valueQuote,
                                                                System.Collections.Generic.Dictionary <string, string> lookupDictionary)
        {
            if (arguments != null && item != null && lookupDictionary != null)
            {
                // special for the name
                arguments.Clear();
                System.Collections.Generic.List <string> idenities = new System.Collections.Generic.List <string>(6);

                string name = item.ItemSpec;
                if (!string.IsNullOrEmpty(name))
                {
                    string element = item.GetMetadata(MsDeploy.ExistingParameterValiationMetadata.Element.ToString());
                    if (string.IsNullOrEmpty(element))
                    {
                        element = "parameterEntry";
                    }
                    if (string.Compare(element, "parameterEntry", System.StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        idenities.Add(name);
                        foreach (string dPIdentity in System.Enum.GetNames(typeof(MsDeploy.ExistingDeclareParameterMetadata)))
                        {
                            idenities.Add(item.GetMetadata(dPIdentity));
                        }

                        string identity = string.Join(",", idenities.ToArray());
                        if (!lookupDictionary.ContainsKey(identity))
                        {
                            string nameValue = MsDeploy.Utility.PutValueInQuote(name, valueQuote);
                            arguments.Add(string.Concat("name=", nameValue));
                            System.Type enumType = lookupDictionary.ContainsValue(name) ? typeof(MsDeploy.ExistingDeclareParameterMetadata) : typeof(MsDeploy.DeclareParameterMetadata);
                            // the rest, build on the Enum Name
                            MsDeploy.Utility.BuildArgumentsBaseOnEnumTypeName(item, arguments, enumType, valueQuote);
                            lookupDictionary.Add(identity, name);
                        }
                    }
                    else if (string.Compare(element, "parameterValidation", System.StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        System.Diagnostics.Debug.Assert(false, "msdeploy.exe doesn't support parameterValidation entry in the command line for declareParameter yet.");
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Override the Execute method to be able to send ExternalProjectStarted/Finished events.
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            bool bSuccess = false;

            if (this.PreviewCommandLineOnly)
            {
                // useful information about what was wrong with the parameters.
                if (!ValidateParameters())
                {
                    return(false);
                }
                Log.LogMessage(Framework.MessageImportance.Low, SR.MSDEPLOY_EXE_PreviewOnly);
                return(true);
            }

            try
            {
                Log.LogMessage(Framework.MessageImportance.Normal, SR.MSDEPLOY_EXE_Start);
                bSuccess = base.Execute();
                if (bSuccess)
                {
                    Log.LogMessage(Framework.MessageImportance.Normal, SR.MSDEPLOY_EXE_Succeeded);
                }
            }
            catch (System.Exception ex)
            {
                // Log Failure
                Log.LogMessage(Framework.MessageImportance.High, SR.MSDEPLOY_EXE_Failed);
                Log.LogErrorFromException(ex);
                bSuccess = false;
            }
            if (bSuccess)
            {
                string type = string.Empty;
                string path = string.Empty;
                Framework.ITaskItem taskItem = null;
                if (this.Destination != null && this.Destination.GetLength(0) == 1)
                {
                    taskItem = this.Destination[0];
                }
                else
                {
                    if (this.Source != null)
                    {
                        taskItem = this.Source[0];
                    }
                }
                if (taskItem != null)
                {
                    type = taskItem.ItemSpec;
                    path = taskItem.GetMetadata("Path");
                }
                MsDeploy.Utility.MsDeployExeEndOfExecuteMessage(bSuccess, type, path, Log);
            }
            return(bSuccess);
        }
コード例 #5
0
            private ImmutableArray <string> GetAliases(MSB.Framework.ITaskItem item)
            {
                var aliasesText = item.GetMetadata("Aliases");

                if (string.IsNullOrEmpty(aliasesText))
                {
                    return(ImmutableArray <string> .Empty);
                }

                return(ImmutableArray.CreateRange(aliasesText.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)));
            }
コード例 #6
0
        public static bool Execute(
            #region Parameters
            out Microsoft.Build.Framework.ITaskItem[] Result,
            Microsoft.Build.Framework.ITaskItem[] Items,
            Microsoft.Build.Framework.ITaskItem BaseItem,
            Microsoft.Build.Framework.ITaskItem Template = null)
        #endregion
        {
            #region Code
            Result = new ITaskItem[] { };
            var reserved = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase)
            {
                "AccessedTime", "CreatedTime", "DefiningProjectDirectory",
                "DefiningProjectExtension", "DefiningProjectFullPath", "DefiningProjectName",
                "Directory", "Extension", "Filename", "FullPath", "Identity", "ModifiedTime",
                "RecursiveDir", "RelativeDir", "RootDir",
            };
            var newItems = new List <ITaskItem>();
            foreach (var item in Items)
            {
                var newItem = new TaskItem(item);
                if (BaseItem != null)
                {
                    BaseItem.CopyMetadataTo(newItem);
                }
                var itemExt = newItem.GetMetadata("Extension");
                if (!string.IsNullOrEmpty(itemExt))
                {
                    newItem.SetMetadata("Suffix", itemExt.Substring(1));
                }
                if (Template != null)
                {
                    var metadataNames = Template.MetadataNames
                                        .Cast <string>().Where(x => !reserved.Contains(x));
                    foreach (var metadataName in metadataNames)
                    {
                        var metadataValue = Template.GetMetadata(metadataName);
                        newItem.SetMetadata(metadataName,
                                            Regex.Replace(metadataValue, @"(%<)(\w+)(>)",
                                                          match => newItem.GetMetadata(match.Groups[2].Value)));
                    }
                }
                newItems.Add(newItem);
            }
            Result = newItems.ToArray();
            #endregion

            return(true);
        }
コード例 #7
0
        static public void AddDestinationProviderSettingToObject(Utilities.CommandLineBuilder commandLineBuilder, string dest, Framework.ITaskItem[] items, string valueQuoteChar,
                                                                 Framework.ITaskItem[] additionalProviderItems, MSDeploy msdeploy)
        {
            //commandLineBuilder.AppendSwitchUnquotedIfNotNull("-source:", m_source);
            //commandLineBuilder.AppendSwitchUnquotedIfNotNull("-dest:", m_dest);
            System.Collections.Generic.List <string> arguments = new System.Collections.Generic.List <string>(6);

            if (items != null && items.GetLength(0) == 1)
            {
                Framework.ITaskItem taskItem = items[0];
                string provider  = taskItem.ItemSpec;
                string path      = taskItem.GetMetadata("Path");
                string valueData = MsDeploy.Utility.PutValueInQuote(path, valueQuoteChar);
                string setData   = (string.IsNullOrEmpty(path)) ? provider : string.Concat(provider, "=", valueData);
                arguments.Add(setData);

                //Commonly supported provider settings:
                //    computerName=<name>     Name of remote computer or proxy-URL
                //    wmsvc=<name>            Name of remote computer or proxy-URL for the Web
                //                            Management Service (wmsvc)
                //    userName=<name>         User name to authenticate
                //    password=<password>     Password of user name
                //    encryptPassword=<pwd>   Password to use for encryption related operations
                //    includeAcls=<bool>      If true, include ACLs in the operation for the
                //                            specified path

                foreach (string name in taskItem.MetadataNames)
                {
                    if (!MsDeploy.Utility.IsInternalMsdeployWellKnownItemMetadata(name))
                    {
                        string value = taskItem.GetMetadata(name);
                        if (!string.IsNullOrEmpty(value))
                        {
                            valueData = MsDeploy.Utility.PutValueInQuote(value, valueQuoteChar);
                            setData   = string.Concat(name, "=", valueData);
                            arguments.Add(setData);
                        }
                    }
                    else
                    {
                        MsDeploy.Utility.IISExpressMetadata expressMetadata;
                        if (System.Enum.TryParse <MsDeploy.Utility.IISExpressMetadata>(name, out expressMetadata))
                        {
                            string value = taskItem.GetMetadata(name);
                            if (!string.IsNullOrEmpty(value))
                            {
                                switch (expressMetadata)
                                {
                                case Utility.IISExpressMetadata.WebServerAppHostConfigDirectory:
                                    msdeploy.WebServerAppHostConfigDirectory = value;
                                    break;

                                case Utility.IISExpressMetadata.WebServerDirectory:
                                    msdeploy.WebServerDirectory = value;
                                    break;

                                case Utility.IISExpressMetadata.WebServerManifest:
                                    msdeploy.WebServerManifest = value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            // If additional parameters are specified, we add these too. the itemSpec will be something like iisApp, contentPath, etc and
            // each item should have a name\value pair defined as metadata. Each provider will be written as itemSpec.Name=Value
            if (additionalProviderItems != null)
            {
                foreach (Framework.ITaskItem item in additionalProviderItems)
                {
                    if (!string.IsNullOrEmpty(item.ItemSpec))
                    {
                        string settingName  = item.GetMetadata("Name");
                        string settingValue = item.GetMetadata("Value");
                        if (!string.IsNullOrEmpty(settingName) && !string.IsNullOrEmpty(settingValue))
                        {
                            string providerString = string.Concat(item.ItemSpec, ".", settingName, "=", settingValue);
                            arguments.Add(providerString);
                        }
                    }
                }
            }

            commandLineBuilder.AppendSwitchUnquotedIfNotNull(dest, arguments.Count == 0 ? null : string.Join(",", arguments.ToArray()));
            return;
        }
コード例 #8
0
ファイル: ProjectFile.cs プロジェクト: singhsarab/roslyn
 protected static bool IsDocumentLinked(MSB.Framework.ITaskItem documentItem)
 {
     return(!string.IsNullOrEmpty(documentItem.GetMetadata("Link")));
 }
コード例 #9
0
ファイル: ProjectFile.cs プロジェクト: singhsarab/roslyn
 protected bool IsProjectReferenceOutputAssembly(MSB.Framework.ITaskItem item)
 {
     return(item.GetMetadata("ReferenceOutputAssembly") == "true");
 }