Example #1
0
        public override void Execute()
        {
            if (ExcludeCondition)
            {
                return;
            }
            if (!AdditionalCondition)
            {
                return;
            }

            DTE     dte     = (DTE)this.GetService(typeof(DTE));
            Project project = this.GetTargetProject(dte);

            string evaluatedTemplateFileName = EvaluateParameterAsString(dte, TemplateFileName);


            string templateContent = GenerateContent(evaluatedTemplateFileName, "Resources.resx");

            if (Helpers2.TemplateContentIsEmpty(templateContent))
            {
                //do nothing if no content has been generated
                return;
            }

            //get the project where we pla
            Project globalresproject = Helpers.GetResourcesProject(dte);
            Project selectedproject  = Helpers.GetSelectedProject(dte);

            string resourcesFilename = "";

            if (FeatureResources)
            {
                //for feature resources name is "Resources.resx"
                resourcesFilename = "Resources.resx";
            }
            else if (ApplicationResources)
            {
                resourcesFilename = Helpers.GetOutputNameWithoutExtensions(selectedproject) + ".AppResources.resx";
            }
            else
            {
                //global resources get the name of the current project project
                resourcesFilename = Helpers.GetOutputNameWithoutExtensions(selectedproject) + ".resx";
            }

            //1. find a resourcefile
            if (ApplicationResources)
            {
                if (globalresproject != null)
                {
                    //global resources project -> use the file 12/resources
                    AddApplicationResources(globalresproject, resourcesFilename, templateContent);
                }
                else
                {
                    AddApplicationResources(selectedproject, resourcesFilename, templateContent);
                }
            }
            else if (FeatureResources)
            {
                string evaluatedFeatureName = EvaluateParameterAsString(dte, FeatureName);

                //Find the feature folder

                ProjectItem folderOfFeature = Helpers2.GetFolderOfFeature(project, evaluatedFeatureName);
                if (folderOfFeature != null)
                {
                    if (Helpers2.IsSharePointVSTemplate(dte, project))
                    {
                        //put resources.resx directly into under the feature
                        AddResourcesToFolder(folderOfFeature, resourcesFilename, templateContent);
                    }
                    else
                    {
                        //now add a folder "Resources" in the feature and put the "Resource.<culture>.resx" there
                        ProjectItems whereToAdd = Helpers.GetProjectItemsByPath(folderOfFeature.ProjectItems, "Resources");
                        AddResourcesToFolder(whereToAdd.Parent as ProjectItem, resourcesFilename, templateContent);
                    }
                }
            }
            else if (AdminResources)
            {
                //put the content into
                if (globalresproject != null)
                {
                    //global resources project -> use the file 12/resources
                    AddAdminResources(globalresproject, resourcesFilename, templateContent);
                }
                else
                {
                    AddAdminResources(selectedproject, resourcesFilename, templateContent);
                }
            }
            else
            {
                //put the content into
                if (globalresproject != null)
                {
                    //global resources project -> use the file 12/resources
                    AddGlobalResources(globalresproject, resourcesFilename, templateContent);
                }
                else
                {
                    AddGlobalResources(selectedproject, resourcesFilename, templateContent);
                }
            }
        }