Example #1
0
        private void ResolveProjectReferences(VSLangProj.VSProject project,
                                              Dictionary <string, ReferenceModel> availableReplaceReferences, Dictionary <string, ReferenceModel> referencesThanMustBeAdded)
        {
            this.Worker.ReportProgress(50, GetAction(() => { this.Info.DoOnProjectModifyingStart(project); }));

            VSLangProj.References               existingRefs = project.References;
            List <VSLangProj.Reference>         refsToRemove;
            Dictionary <string, ReferenceModel> refsToAdd;

            this.GetReferencesToAddAndRemove(existingRefs, availableReplaceReferences, referencesThanMustBeAdded, out refsToRemove, out refsToAdd);

            for (int i = 0; i < refsToRemove.Count; i++)
            {
                VSLangProj.Reference refToRemove      = refsToRemove[i];
                ReferenceModel       refModelToRemove = new ReferenceModel(refToRemove.Name, refToRemove.Path);
                refToRemove.Remove();
                this.Worker.ReportProgress(50, GetAction(() => { this.Info.DoOnReferenceRemoved(refModelToRemove); }));
            }

            foreach (KeyValuePair <string, ReferenceModel> refToAdd in refsToAdd)
            {
                existingRefs.Add(refToAdd.Value.Path);
                this.Worker.ReportProgress(50, GetAction(() => { this.Info.DoOnReferenceAdded(refToAdd.Value); }));
            }

            this.Worker.ReportProgress(50, GetAction(() => { this.Info.DoOnProjectModifyingEnd(project); }));
        }
        protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
        {
            VSLangProj.Reference reference = _project.VSLangProj_References.Find("System.Drawing");
            if (reference != null)
            {
                reference.Remove();
            }

            string spotGraphics = "Microsoft.SPOT.Graphics";

            reference = _project.VSLangProj_References.Find(spotGraphics);
            if (reference == null)
            {
                _project.VSLangProj_References.Add(spotGraphics);
            }

            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);
            string       inputFileNameWithoutExtension = Path.GetFileNameWithoutExtension(inputFileName);

            Assembly tasks = null;

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (string.Compare(asm.GetName().Name, "Microsoft.SPOT.Tasks", true) == 0)
                {
                    if (asm.GetName().Version.ToString(2) == new Version(_project.GetTargetFrameworkProperty().TrimStart('v')).ToString(2))
                    {
                        tasks = asm;
                        break;
                    }
                }
            }

            if (tasks == null)
            {
                throw new Exception("Microsoft.SPOT.Tasks.dll is not loaded!");
            }

            Type typ = tasks.GetType("Microsoft.SPOT.Tasks.ProcessResourceFiles");

            if (typ != null)
            {
                object processResourceFiles = typ.GetConstructor(new Type[] {}).Invoke(null);

                typ.GetProperty("StronglyTypedClassName").SetValue(processResourceFiles, inputFileNameWithoutExtension, null);
                typ.GetProperty("StronglyTypedNamespace").SetValue(processResourceFiles, GetResourcesNamespace(), null);
                typ.GetProperty("GenerateNestedEnums").SetValue(processResourceFiles, m_fNestedEnums, null);
                typ.GetProperty("GenerateInternalClass").SetValue(processResourceFiles, m_fInternal, null);
                typ.GetProperty("IsMscorlib").SetValue(processResourceFiles, m_fMscorlib, null);

                string resourceName = (string)typ.GetProperty("StronglyTypedNamespace").GetValue(processResourceFiles, null);

                if (string.IsNullOrEmpty(resourceName))
                {
                    resourceName = inputFileNameWithoutExtension;
                }
                else
                {
                    resourceName = string.Format("{0}.{1}", resourceName, inputFileNameWithoutExtension);
                }

                typ.GetMethod("CreateStronglyTypedResources").Invoke(processResourceFiles, new object[] { inputFileName, this.CodeProvider, writer, resourceName });
            }

            return(base.StreamToBytes(stream));
        }