private static void TrySetHintPath(VSLangProj80.Reference3 reference)
        {
            try
            {
                Microsoft.Build.Evaluation.Project project =
                    MSBuildUtils.LoadedProject(reference.ContainingProject.FullName, false, false);

                Microsoft.Build.Evaluation.ProjectItem item =
                    project.AllEvaluatedItems.FirstOrDefault(i =>
                                                             i.ItemType.Equals("Reference") &&
                                                             i.EvaluatedInclude.Split(",".ToCharArray()).ElementAt(0).Equals(reference.Name)
                                                             );
                if (item != null)
                {
                    item.SetMetadataValue("HintPath", Path.Combine("$(IceAssembliesDir)",
                                                                   string.Format("{0}.dll", reference.Name)));
                }
            }
            catch (NotSupportedException)
            {
            }
            catch (NotImplementedException)
            {
            }
            catch (COMException)
            {
            }
        }
 private static void TrySetCopyLocal(VSLangProj80.Reference3 reference)
 {
     //
     // Always set copy local to true for references that we add
     //
     try
     {
         //
         // In order to properly write this to MSBuild in ALL cases, we have to trigger the Property Change
         // notification with a new value of "true". However, "true" is the default value, so in order to
         // cause a notification to fire, we have to set it to false and then back to true
         //
         reference.CopyLocal = false;
         reference.CopyLocal = true;
     }
     catch (NotSupportedException)
     {
     }
     catch (NotImplementedException)
     {
     }
     catch (COMException)
     {
     }
 }
        public static bool AddAssemblyReference(EnvDTE.Project project, string assembliesDir, string component)
        {
            string path = Path.Combine(assembliesDir, string.Format("{0}.dll", component));

            VSLangProj.VSProject vsProject = (VSLangProj.VSProject)project.Object;
            try
            {
                VSLangProj80.Reference3 reference = (VSLangProj80.Reference3)vsProject.References.Add(path);
                TrySetCopyLocal(reference);
                TrySetSpecificVersion(reference);
                TrySetHintPath(reference);
                return(true);
            }
            catch (COMException)
            {
            }
            return(false);
        }
 public static bool AddAssemblyReference(EnvDTE.Project project, String component)
 {
     VSLangProj.VSProject vsProject = (VSLangProj.VSProject)project.Object;
     try
     {
         VSLangProj80.Reference3 reference = (VSLangProj80.Reference3)vsProject.References.Add(component + ".dll");
         reference.CopyLocal = true;
         //
         // We set SpecificVersion to false so that references still work
         // when Ice Home setting is updated.
         //
         reference.SpecificVersion = false;
         return(true);
     }
     catch (COMException)
     {
     }
     return(false);
 }
 private static void TrySetSpecificVersion(VSLangProj80.Reference3 reference)
 {
     //
     // Allways set SpecificVersion to false so that references still work
     // when Ice Home setting is updated.
     //
     try
     {
         reference.SpecificVersion = true;
         reference.SpecificVersion = false;
     }
     catch (NotSupportedException)
     {
     }
     catch (NotImplementedException)
     {
     }
     catch (COMException)
     {
     }
 }
        private static bool UpgradeCSharpConfiguration(EnvDTE.Project dteProject,
                                                       Microsoft.Build.Evaluation.Project project, OldConfiguration cfg)
        {
            ProjectPropertyGroupElement propertyGroup = project.Xml.PropertyGroups.FirstOrDefault(g => g.Label.Equals("IceBuilder"));

            if (propertyGroup == null)
            {
                propertyGroup       = project.Xml.AddPropertyGroup();
                propertyGroup.Label = "IceBuilder";
            }

            if (!string.IsNullOrEmpty(cfg.OutputDir))
            {
                propertyGroup.AddProperty(PropertyNames.OutputDir, cfg.OutputDir);
            }

            if (!string.IsNullOrEmpty(cfg.AdditionalOptions))
            {
                propertyGroup.AddProperty(PropertyNames.AdditionalOptions, cfg.AdditionalOptions);
            }

            if (!string.IsNullOrEmpty(cfg.IncludeDirectories))
            {
                propertyGroup.AddProperty(PropertyNames.IncludeDirectories,
                                          string.Format(@"{0};$(IceHome)\slice", cfg.IncludeDirectories));
            }
            else
            {
                propertyGroup.AddProperty(PropertyNames.IncludeDirectories, @"$(IceHome)\slice");
            }

            if (cfg.Stream)
            {
                propertyGroup.AddProperty(PropertyNames.Stream, "True");
            }

            if (cfg.Checksum)
            {
                propertyGroup.AddProperty(PropertyNames.Checksum, "True");
            }

            if (cfg.Ice)
            {
                propertyGroup.AddProperty(PropertyNames.AllowIcePrefix, "True");
            }

            if (cfg.Tie)
            {
                propertyGroup.AddProperty(PropertyNames.Tie, "True");
            }

            foreach (string assembly in Package.AssemblyNames)
            {
                VSLangProj80.Reference3 reference = ProjectUtil.FindAssemblyReference(dteProject, assembly) as VSLangProj80.Reference3;
                if (reference != null)
                {
                    reference.SpecificVersion = false;
                }
            }

            List <ProjectItem> sliceItems =
                project.GetItems("None").Where(item => Path.GetExtension(item.UnevaluatedInclude).Equals(".ice")).ToList();

            //
            // Default output directory has changed
            //
            if (string.IsNullOrEmpty(cfg.OutputDir))
            {
                project.GetItems("Compile").Where(
                    item =>
                {
                    return(sliceItems.FirstOrDefault(
                               slice =>
                    {
                        return slice.UnevaluatedInclude.Equals(Path.ChangeExtension(item.UnevaluatedInclude, ".ice"));
                    }) != null);
                })
                .ToList()
                .ForEach(item => project.RemoveItem(item));
            }

            return(true);
        }