public VSProjectConfiguration( VSProject project, Bam.Core.Module module, Bam.Core.EPlatform platform) { this.Project = project; this.Module = module; this.Configuration = module.BuildEnvironment.Configuration; this.Platform = platform; this.FullName = this.CombinedName; this.Type = EType.NA; var visualCMeta = Bam.Core.Graph.Instance.PackageMetaData<VisualC.MetaData>("VisualC"); this.PlatformToolset = visualCMeta.PlatformToolset; this.UseDebugLibraries = false; this.CharacterSet = C.ECharacterSet.NotSet; this.WholeProgramOptimization = false;// TODO: false is consistent with Native builds (module.BuildEnvironment.Configuration != Bam.Core.EConfiguration.Debug); this.SettingGroups = new Bam.Core.Array<VSSettingsGroup>(); this.Sources = new Bam.Core.Array<VSSettingsGroup>(); this.PreBuildCommands = new Bam.Core.StringArray(); this.PostBuildCommands = new Bam.Core.StringArray(); }
/// <summary>Initializes a new instance of the <see cref="ProjectModel"/> class. </summary> /// <param name="project">The native project object. </param> public ProjectModel(VSProject project) { _vsProject = project; Name = project.Project.Name; LoadReferences(); }
public VsProjectReferencesTracker(Project project, DteWithEvents dteWithEvents, IIdeTracer tracer) { this.project = project.Object as VSProject; this.dteWithEvents = dteWithEvents; this.tracer = tracer; this.timer = new Timer(HandleFilesChangedOnDisk, null, Timeout.Infinite, Timeout.Infinite); this.triggerReferenceChangedTimer = new Timer(TriggerReferenceChange, null, Timeout.Infinite, Timeout.Infinite); }
public static IEnumerable<CodeClass2> GetMCClasses(VSProject vsproject) { return vsproject .Project .ProjectItems .Cast<ProjectItem>() .SelectMany(GetMCClasses); }
public AddWebGACReference(WebGAC.Core.WebGAC pGac, VSProject pVsProj, string pCurrentConfiguration, string[] pAllConfigurations) { InitializeComponent(); mVsProj = pVsProj; mCurrentConfiguration = pCurrentConfiguration; mAllConfigurations = pAllConfigurations; mGac = pGac; }
private void AssertCanLoadProject( string resourceName ) { string fileName = Path.GetFileNameWithoutExtension( resourceName ); using( TempResourceFile file = new TempResourceFile( this.GetType(), resourceDir + "." + resourceName, resourceName ) ) { VSProject project = new VSProject( file.Path ); Assert.AreEqual( fileName, project.Name ); Assert.AreEqual( Path.GetFullPath( file.Path ), project.ProjectPath ); Assert.AreEqual( fileName.ToLower(), Path.GetFileNameWithoutExtension( project.Configs[0].Assemblies[0].ToString().ToLower() ) ); } }
public void GenerateCorrectExtensionsFromVCProjectVS2005() { using (TempResourceFile file = new TempResourceFile(this.GetType(), "resources.cpp-default-library_VS2005.vcproj", "cpp-default-library_VS2005.vcproj")) { VSProject project = new VSProject(file.Path); Assert.AreEqual("cpp-default-library_VS2005", project.Name); Assert.AreEqual(Path.GetFullPath(file.Path), project.ProjectPath); Assert.AreEqual(Path.GetFullPath( TestPath( @"debug/cpp-default-library_VS2005.dll" ) ).ToLower(), project.Configs["Debug|Win32"].Assemblies[0].ToString().ToLower()); Assert.AreEqual(Path.GetFullPath( TestPath( @"release/cpp-default-library_VS2005.dll" ) ).ToLower(), project.Configs["Release|Win32"].Assemblies[0].ToString().ToLower()); } }
// Token: 0x06000027 RID: 39 RVA: 0x00002B98 File Offset: 0x00000D98 private IUnresolvedFile[] GetFiles(VSProject vsproject) { string[] files = this.GetFilePaths(vsproject); IUnresolvedFile[] projectFiles = new IUnresolvedFile[files.Length]; ParallelOptions parallelOptions = new ParallelOptions { TaskScheduler = TaskScheduler.Default }; Parallel.For(0, files.Length, parallelOptions, delegate(int i) { projectFiles[i] = this.LoadFile(files[i]); }); return(projectFiles); }
/// <summary> /// Adds the entity framework section to an existing web config file. /// </summary> /// <param name="EFVersion">The Entity Framework version.</param> /// <param name="mySqlVersion">The My SQL version.</param> private void AddEntityFrameworkSection(string EFVersion, string mySqlVersion) { Project activeProj = null; VSProject vsProj = null; DTE2 vsApp = MySqlDataProviderPackage.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; Array activeProjects = (Array)vsApp.ActiveSolutionProjects; if (activeProjects.Length > 0) { activeProj = (Project)activeProjects.GetValue(0); vsProj = activeProj.Object as VSProject; string projectPath = System.IO.Path.GetDirectoryName(activeProj.FullName); WebConfigTools.EFWebConfigTransformation(projectPath, EFVersion, mySqlVersion, _mySQLEF6Version); } }
/// <summary> /// Removes the entity framework section from an existing web config file. /// </summary> private void RemoveEntityFrameworkSection() { Project activeProj = null; VSProject vsProj = null; DTE2 vsApp = MySqlDataProviderPackage.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; Array activeProjects = (Array)vsApp.ActiveSolutionProjects; if (activeProjects.Length > 0) { activeProj = (Project)activeProjects.GetValue(0); vsProj = activeProj.Object as VSProject; string projectPath = System.IO.Path.GetDirectoryName(activeProj.FullName); WebConfigTools.RemoveEFWebConfig(projectPath); } }
public NUnitProject ConvertFrom(string path) { if (VSProject.IsProjectFile(path)) { return(ConvertVSProject(path)); } else if (VSProject.IsSolutionFile(path)) { return(Services.UserSettings.GetSetting("Options.TestLoader.VisualStudio.UseSolutionConfigs", true) ? ConvertVSSolution(path) : LegacyConvertVSSolution(path)); } return(null); }
public void AssertFileIsInProject(string fileName) { const string ProjectFileName = @"..\..\..\ProjectPilot.Tests\ProjectPilot.Tests.csproj"; VSProject project = VSProject.Load(ProjectFileName); foreach (VSProjectItem item in project.Items) { if (item.Item == fileName) { return; } } Assert.Fail("{0} file is missing from the project data", fileName); }
public void TestParsingVSProjectFile3() { VSProject project = VSProject.Load(@"..\..\..\Data\Samples\Hsl.Ganesha.DBAccess.csproj"); IList <VSProjectItem> compileItems = project.GetSingleTypeItems(VSProjectItem.CompileItem); IList <VSProjectItem> referenceItems = project.GetSingleTypeItems(VSProjectItem.Reference); Assert.AreEqual(3, compileItems.Count); Assert.AreEqual(2, project.Configurations.Count); Assert.AreEqual(3, referenceItems.Count); Assert.AreEqual(15, project.Properties.Count); Assert.AreEqual(@"Properties\AssemblyInfo.cs", compileItems.ElementAt(2).Item); Assert.AreEqual("System.Data", project.Items[1].Item); }
// Token: 0x06000028 RID: 40 RVA: 0x00002C08 File Offset: 0x00000E08 private IAssemblyReference[] GetReferences(VSProject vsproject) { string[] assemblies = this.GetReferencesPaths(vsproject); IUnresolvedAssembly[] projectContents = new IUnresolvedAssembly[assemblies.Length]; ParallelOptions parallelOptions = new ParallelOptions { TaskScheduler = TaskScheduler.Default }; Parallel.For(0, assemblies.Length, parallelOptions, delegate(int i) { projectContents[i] = this.LoadAssembly(assemblies[i]); }); return(projectContents); }
/// <summary> /// Is the project hosting the Store actually referencing an assembly? /// </summary> /// <param name="store">Modeling Store containing the model of interest</param> /// <param name="assemblyName">Assembly name for which we want to know if it is referenced by the /// project hosting the model contained in the store /// </param> /// <returns><c>true</c> if the assembly is referenced by the project hosting the store, and <c>false</c> otherwise</returns> public static bool IsHostingProjectReferencingAssembly(Store store, string assemblyName) { Project project = Store2DTE.GetProjectForStore(store); // Case where the Dsl was open outside a project. if (project == null) { return(false); } // Add references. VSProject vsProject = project.Object as VSProject; return(vsProject.References.OfType <Reference>().FirstOrDefault(reference => reference.Name == assemblyName) != null); }
private IEnumerator <Project> IterateProjectReferences(VSProject vsProject) { if (vsProject.References == null) { yield break; } foreach (Reference reference in vsProject.References) { if (reference.SourceProject != null) { yield return(reference.SourceProject); } } }
/// <summary> /// Adds a binary reference to a project in the solution. /// </summary> /// <param name="p">The destination project</param> /// <param name="basePath">The base path.</param> private void AddBinaryReferences(Project destination) { VSProject proj = destination.Object as VSProject; AddReference(proj, m_dstPath + "Lib\\AndroMDA.NHibernateSupport.dll"); AddReference(proj, m_dstPath + "Lib\\Castle.DynamicProxy.dll"); //AddReference(proj, m_dstPath + "Lib\\HashCodeProvider.dll"); AddReference(proj, m_dstPath + "Lib\\Iesi.Collections.dll"); AddReference(proj, m_dstPath + "Lib\\log4net.dll"); AddReference(proj, m_dstPath + "Lib\\NHibernate.Caches.SysCache.dll"); AddReference(proj, m_dstPath + "Lib\\NHibernate.dll"); //AddReference(proj, m_dstPath + "Lib\\NHibernate.Nullables2.dll"); AddReference(proj, m_dstPath + "Lib\\Nullables.dll"); AddReference(proj, m_dstPath + "Lib\\Nullables.NHibernate.dll"); }
public Reference[] GetReferencesListeNoInSolution() { VSProject vsproj = project.Object as VSProject; List <Reference> prjs = new List <Reference>(); foreach (Reference item in vsproj.References.OfType <Reference>()) { if (item.SourceProject == null) { prjs.Add(item); } } return(prjs.ToArray()); }
public void LoadCppProjectWithMacros() { using (TestResource file = new TestResource("CPPLibrary.vcproj")) { VSProject project = new VSProject(file.Path); Assert.AreEqual("CPPLibrary", project.Name); Assert.AreEqual(Path.GetFullPath(file.Path), project.ProjectPath); Assert.AreEqual( Path.Combine(Path.GetTempPath(), @"debug\cpplibrary.dll").ToLower(), project.Configs["Debug|Win32"].Assemblies[0].ToString().ToLower()); Assert.AreEqual( Path.Combine(Path.GetTempPath(), @"release\cpplibrary.dll").ToLower(), project.Configs["Release|Win32"].Assemblies[0].ToString().ToLower()); } }
public void GenerateCorrectExtensionsFromVCProjectVS2005() { using (TestResource file = new TestResource("cpp-default-library_VS2005.vcproj")) { VSProject project = new VSProject(file.Path); Assert.AreEqual("cpp-default-library_VS2005", project.Name); Assert.AreEqual(Path.GetFullPath(file.Path), project.ProjectPath); Assert.AreEqual( Path.Combine(Path.GetTempPath(), TestPath(@"debug/cpp-default-library_VS2005.dll")).ToLower(), project.Configs["Debug|Win32"].Assemblies[0].ToString().ToLower()); Assert.AreEqual( Path.Combine(Path.GetTempPath(), TestPath(@"release/cpp-default-library_VS2005.dll")).ToLower(), project.Configs["Release|Win32"].Assemblies[0].ToString().ToLower()); } }
private static IEnumerable <ProjectReferenceToAdd> FindChanges(Project projectAdded) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); string assemblyName = projectAdded.GetAssemblyName(); var solution = projectAdded.DTE.Solution; Microsoft.Build.Evaluation.Project buildProjAdded = ProjectCollection.GlobalProjectCollection.GetLoadedProjects(projectAdded.FullName).First(); var changes = new List <ProjectReferenceToAdd>(); foreach (Project project in solution.Projects) { if (project.UniqueName == projectAdded.UniqueName) { continue; } VSProject vsProject = project.Object as VSProject; if (vsProject == null) { continue; } foreach (Reference reference in vsProject.References) { //If this project already has a project reference to the project being added then we don't need to do anything. if (reference.SourceProject != null && projectAdded == reference.SourceProject) { break; } if (Path.GetFileNameWithoutExtension(reference.Path).Equals(assemblyName)) { changes.Add(new ProjectReferenceToAdd { Reference = reference, Project = vsProject, ProjectToReference = projectAdded } ); } } } return(changes); }
/// <summary> /// This method determines whether the given type comes from the current project, its temporary assemblies or references. /// </summary> /// <param name="t">The type in question</param> /// <param name="vsProject">The project we planning to add domain service to</param> /// <param name="projectReferences">References collection for the project</param> /// <returns><c>true</c> if the type is visible, <c>false</c> otherwise</returns> private static bool IsVisibleInCurrentProject(Type t, VSProject vsProject, IEnumerable <Reference> projectReferences) { // If we couldn't retirve project or references info -- return true so that the type will appear in the wizard if (t == null || vsProject == null || projectReferences == null) { return(true); } Assembly typeAssembly = t.Assembly; string typeAssemblyName = typeAssembly.GetName().Name; Project project = vsProject.Project; // Check if type comes from this project's output assembly string projectAssemblyName = (string)project.Properties.Item("AssemblyName").Value; if (typeAssemblyName.Equals(projectAssemblyName, StringComparison.Ordinal)) { return(true); } // Check if type's assembly is located under project's obj directory string relativeObjDirectory = project.ConfigurationManager.ActiveConfiguration.Properties.Item("IntermediatePath").Value as string; string projectObjDirectory = Path.Combine(Path.GetDirectoryName(project.FullName), relativeObjDirectory); if (typeAssembly.Location.StartsWith(projectObjDirectory, StringComparison.OrdinalIgnoreCase)) { return(true); } // Check if type comes from one of the project's references foreach (Reference reference in projectReferences) { // If Identity property contains tailing '\0' -- remove it. string referenceName = reference.Identity; if (referenceName.EndsWith(Char.ToString((char)0), StringComparison.Ordinal)) { referenceName = referenceName.Substring(0, referenceName.Length - 1); } if (referenceName.Equals(typeAssemblyName, StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
/// <summary> /// Finds the type of the code element from the specified project. /// </summary> /// <param name="project">The project.</param> /// <param name="typeName">Name of the type.</param> /// <param name="elementKind">Kind of the element.</param> /// <returns> /// The <see cref="CodeElement"/> found or null if no matches. /// </returns> public static CodeElement FindCodeElementFromType(Project project, string typeName, vsCMElement elementKind) { if (project == null || string.IsNullOrEmpty(typeName)) { return(null); } // try to find it in the selected project CodeElement result = FindCodeElementByFullName(project, typeName, elementKind); if (result == null) { // navigate through the project references and look into each project if (!DteHelper.IsWebProject(project)) { VSProject vsProject = project.Object as VSProject; foreach (Reference reference in vsProject.References) { result = FindCodeElementFromType(reference.SourceProject, typeName, elementKind); if (result != null && result.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject) { break; } } } else { VSWebSite webProject = project.Object as VSWebSite; if (webProject != null) { foreach (AssemblyReference reference in webProject.References) { Project sourceProject = GetSourceProject(reference); result = FindCodeElementFromType(sourceProject, typeName, elementKind); if (result != null && result.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject) { break; } } } } } return(result); }
protected override bool CanExecute(OleMenuCommand command) { if (base.CanExecute(command)) { var project = VsShellHelper.Dte.SelectedItems.Item(1).Project; if (project != null && project.Kind == PrjKind.prjKindCSharpProject) { //Executed at the project level return(true); } var projectItem = VsShellHelper.Dte.SelectedItems.Item(1).ProjectItem; if (projectItem != null) { //Executed at the folder level / item level if (projectItem.FileCodeModel != null && projectItem.FileCodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp) { return(true); } //TODO:probably a folder inside the solution return(true); } //Executed at the solution level var selectedHierarchy = VsShellHelper.GetSelectedHierarchy(); if (selectedHierarchy != null) { Project selectedProject = selectedHierarchy.ToProject(); if (selectedProject != null) { VSProject vsProject = selectedProject.Object as VSProject; if (vsProject != null) { return(true); } return(false); } } else if (VsShellHelper.Dte.Solution.IsOpen) { return(true); } return(false); } return(false); }
protected virtual void HandleDefaultReferenciesForProjectOptions(VSProject project, M2ProjectOptions options) { // adding correct switch (options.ProjectPlatform) { case ProjectPlatform.SP2013SSOM: { project.References.Add("Microsoft.SharePoint"); project.References.Add("Microsoft.SharePoint.Security"); if (options.ProjectType == ProjectType.Standard) { project.References.Add("Microsoft.SharePoint.Portal"); project.References.Add("Microsoft.SharePoint.Publishing"); project.References.Add("Microsoft.SharePoint.Taxonomy"); } } break; case ProjectPlatform.SP2013CSOM: { project.References.Add("Microsoft.SharePoint.Client"); project.References.Add("Microsoft.SharePoint.Client.Runtime"); if (options.ProjectType == ProjectType.Standard) { project.References.Add("Microsoft.SharePoint.Client.Publishing"); project.References.Add("Microsoft.SharePoint.Client.Taxonomy"); } } break; case ProjectPlatform.O365CSOM: { // skip it, it'll be via NuGet //project.References.Add("Microsoft.SharePoint.Client"); //project.References.Add("Microsoft.SharePoint.Client.Runtime"); //if (options.ProjectType == ProjectType.Standard) //{ // project.References.Add("Microsoft.SharePoint.Client.Publishing"); // project.References.Add("Microsoft.SharePoint.Client.Taxonomy"); //} } break; } }
public CodeGenerationContext(Model model, string nameSpace, string processID, string modelFileFullName, ITextTemplatingEngineHost textTemplatingHost) { CompileUnit = new CodeCompileUnit(); Model = model; if (string.IsNullOrEmpty(Model.Namespace)) { Namespace = nameSpace; } else { Namespace = Model.Namespace; } DTE = DTEHelper.GetDTE(processID); TextTemplatingHost = textTemplatingHost; ModelFileName = modelFileFullName; ProjectItem = DTE.Solution.FindProjectItem(ModelFileName); AssemblyName = DTEHelper.GetAssemblyName(ProjectItem.ContainingProject); Language = DTEHelper.GetProjectLanguage(ProjectItem.ContainingProject); switch (Language) { case CodeLanguage.CSharp: Provider = new CSharpCodeProvider(); break; case CodeLanguage.VB: Provider = new VBCodeProvider(); // use VB default namespace if it was set VSProject project = (VSProject)ProjectItem.ContainingProject.Object; Property DefaultNamespaceProperty = project.Project.Properties.Item("DefaultNamespace"); DefaultNamespace = (string)DefaultNamespaceProperty.Value; break; default: throw new ArgumentException( "Unsupported project type. ActiveWriter currently supports C# and Visual Basic.NET projects."); } Output = new OutputWindowHelper(DTE); }
/// <summary> /// Adds the reference. /// </summary> /// <param name="instance">The instance.</param> /// <param name="destinationFolder">The destination folder.</param> /// <param name="destination">The destination.</param> /// <param name="source">The source.</param> /// <param name="addFileToFolder">if set to <c>true</c> [add file to folder].</param> public static void AddReference( this Project instance, string destinationFolder, string destination, string source, bool addFileToFolder) { TraceService.WriteLine("ProjectExtensions::AddReference project=" + instance.Name); if (destination.EndsWith(";")) { destination = destination.TrimEnd(';'); } if (destination.EndsWith(".dll") == false) { destination += ".dll"; } if (source.EndsWith(";")) { source = source.TrimEnd(';'); } if (source.EndsWith(".dll") == false) { source += ".dll"; } //// only do if destination file doesn't exist if (File.Exists(destination) == false) { File.Copy(source, destination, true); if (addFileToFolder) { instance.AddToFolderFromFile(destinationFolder, destination); } //// now add a reference to the file VSProject studioProject = instance.Object as VSProject; if (studioProject != null) { studioProject.References.Add(destination); } } }
/// <summary> /// 获取所有的项目 /// </summary> /// <param name="app"></param> /// <returns></returns> public static List <Project> GetAllProjects(DTE2 app) { List <Project> pros = new List <Project>(); if (app.Solution != null) { Solution sol = app.Solution; if (sol.Projects != null && sol.Projects.Count > 0) { foreach (Project topProj in sol.Projects) { GetAllChildProjects(topProj, ref pros); } } } //剔除pros[i].Object不是VSProject的特殊项目 for (int i = 0; i < pros.Count; i++) { VSProject vsProj = pros[i].Object as VSProject; if (vsProj == null) { pros.RemoveAt(i); i--; } } //按照项目名称进行排序 List <string> nameList = new List <string>(); for (int i = 0; i < pros.Count; i++) { nameList.Add(pros[i].Name); } nameList.Sort(); List <Project> rlt = new List <Project>(); for (int i = 0; i < nameList.Count; i++) { for (int j = 0; j < pros.Count; j++) { if (pros[j].Name == nameList[i]) { rlt.Add(pros[j]); break; } } } return(rlt); }
public VSProject GetVSProject() { VSProject p = ExplorerForms.ef.GetVSProject(); if (p != null) { vp = p; return(vp); } if (p == null) { p = ExplorerForms.ef.GetVSSolution().MainVSProject; } vp = p; return(vp); }
private void SubscribeToReferenceChanges(VSProject project, string projectName) { var referencesEvents = project.Events.ReferencesEvents; AmmyProject cachedProject; referencesEvents.ReferenceAdded += reference => { _projectCaches.TryRemove(projectName, out cachedProject); }; referencesEvents.ReferenceChanged += reference => { _projectCaches.TryRemove(projectName, out cachedProject); }; referencesEvents.ReferenceRemoved += reference => { _projectCaches.TryRemove(projectName, out cachedProject); }; _eventContainers.Add(referencesEvents); }
public void RenderResourceFileAndAddToProject( string newFileName, string destDir, VSProject FunctoidVSProject, bool Embedded) { string NewFileName = RenderResourceFile(newFileName, destDir); EnvDTE.ProjectItem FunctoidProjectItem = FunctoidVSProject.Project.ProjectItems.AddFromFile(NewFileName); if (Embedded) { FunctoidProjectItem.Properties.Item("BuildAction").Value = prjBuildAction.prjBuildActionEmbeddedResource; } }
/// <summary> /// Ensures that the VS project hosting a modeling store references a given assembly (by name) /// </summary> /// <param name="store">Modeling store of interest</param> /// <param name="assemblyName">Name of the asssembly for which we want to ensure that it is referenced by the VS project hosting the <paramref name="store"/></param> public static void EnsureProjectReferencesAssembly(Project project, string assemblyName) { // Case where the Dsl was open outside a project. if (project == null) { return; } // Add references. VSProject vsProject = project.Object as VSProject; if (!vsProject.References.OfType <Reference>().Any(reference => reference.Name == assemblyName)) { vsProject.References.Add(assemblyName); } }
private string FindSource(VSProject vp, string method) { VSSolution vs = vp.vs; if (vs == null) { return(""); } Compilation comp = vs.comp[vp.FileName]; if (comp == null) { return(""); } //MessageBox.Show("Compilation found for " + comp.SourceModule.Name); //var sourceText = SourceText.From(text); //Create new document //var doc = ws.AddDocument(project.Id, "NewDoc", sourceText); //Get the semantic model //var model = doc.GetSemanticModelAsync().Result; //Get the syntax node for the first invocation to M() //var methodInvocation = doc.GetSyntaxRootAsync().Result.DescendantNodes().OfType<InvocationExpressionSyntax>().First(); //var methodSymbol = model.GetSymbolInfo(methodInvocation).Symbol; //Finds all references to M() //var referencesToM = SymbolFinder.FindReferencesAsync(methodSymbol, doc.Project.Solution).Result; foreach (SyntaxTree syntaxTree in comp.SyntaxTrees) { var members = syntaxTree.GetRoot().DescendantNodes().OfType <MemberDeclarationSyntax>(); foreach (var member in members) { var methods = member as MethodDeclarationSyntax; if (methods != null) { if (methods.Identifier.Value.ToString() == method) { filename = syntaxTree.FilePath; return(Path.GetFileName(syntaxTree.FilePath) + " line " + methods.GetLocation().SourceSpan.Start); } } } } return(""); }
public void DeleteClipboard(TreeNode nodes) { tv.Nodes.Clear(); tv.FullRowSelect = true; tv.CheckBoxes = true; //if (nc == null) // return; //tv.Nodes.Add(nc); List <TreeNode> n = new List <TreeNode>(); n.Add(nodes); LoadTreeNode(n); target = nodes; //src = GetSourceType(nc); dst = GetSourceType(nodes); //if (src == opers.forms) { MessageBox.Show("Remove items has been selected..."); //string prefix = "";/// sourceprefix(nc); ArrayList L = GetItems(nc); VSProjectItem ps = GetVSProjectItem(target); ArrayList T = GetTargetItems(L, dst); VSProject pp = GetVSProject(nodes); pp.RemoveItems(T); //pp.LoadMetaData(L); //pp.SetItems(T, L); //CopyItems(L, T); return; } }
public static void AddProjectReference(VSProject vsproject, string referenceName) { try { Reference existingReference = vsproject.References.Find(referenceName); if (existingReference != null) { return; } vsproject.References.Add(referenceName); } catch (Exception ex) { ExceptionHandler.LogException(Logger, $"{Resource.ErrorMessage_ErrorAddProjectReference}: {referenceName}", ex); } }
private bool ContainsReference(Project project, string referenceIdentity) { if (project.Name == referenceIdentity) { return(true); } VSProject vsProject = (VSProject)project.Object; foreach (Reference reference in vsProject.References) { if (reference.Name == referenceIdentity) { return(true); } } return(false); }
/// <summary> /// 添加新的引用 /// </summary> /// <param name="project">项目宿体</param> /// <param name="bstrPath">引用的路径(三种形式:1. 简单的.net framework对象名称;2. .net framework文件名;3. COM库文件,这里是COM的完整路径和文件名)</param> /// <returns>Reference对象</returns> public static Reference AddReference(this Project project, string bstrPath) { try { if (null == project || string.IsNullOrEmpty(bstrPath)) { return(null); } VSProject vsProject = project.Object as VSProject; Reference refer = vsProject.References.Add(bstrPath); return(refer); } catch (Exception ex) { throw ex; } }
public Wizard(DTE2 visualStudio, VSProject project) { WizardSteps = new List<IWizardStep>(); _fileService = new FileService(); _fileService.FileLoadedEvent += new FileService.FileLoadedHandler(OnFileLoaded); _fileService.ProgressEvent += new FileService.ProgressHandler(OnProgress); _progress = 0; _visualStudio = visualStudio; _activeProject = project; Configuration = loadConfiguration(project.Project.UniqueName); _singleFileDownload = false; _canceled = false; string userHome = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string configFolder = Path.Combine(userHome, BASE_FOLDER, CONF_FOLDER); Directory.CreateDirectory(configFolder); _configFilePath = Path.Combine(configFolder, _activeProject.Project.UniqueName + ".wizard.conf"); string cachePath = Path.Combine(userHome, BASE_FOLDER, CACHE_FOLDER); Directory.CreateDirectory(cachePath); }
public static ProjectTracker GetOrCreateProjectTracker(VSProject vsProject) { Contract.Requires(vsProject != null); ProjectTracker projectTracker; if (!ProjectIsAvailable(vsProject.Project)) { VSServiceProvider.Current.Logger.WriteToLog("Error: Project is not available! We can't create a 'ProjectTracker'!"); return null; } if (!VSServiceProvider.Current.ProjectTrackers.TryGetValue(vsProject.Project.UniqueName, out projectTracker)) { projectTracker = new ProjectTracker(vsProject); if (vsProject.Project != null && vsProject.Project.UniqueName != null) { VSServiceProvider.Current.ProjectTrackers[vsProject.Project.UniqueName] = projectTracker; } else { // issue: project has no name, so we can't store it. } } return projectTracker; }
public NUnitProject ConvertFrom(string path) { NUnitProject project = new NUnitProject( Path.GetFullPath( path ) ); if ( VSProject.IsProjectFile(path) ) { VSProject vsProject = new VSProject( path ); project.Add( vsProject ); } else if ( VSProject.IsSolutionFile(path) ) { string solutionDirectory = Path.GetDirectoryName( path ); using(StreamReader reader = new StreamReader( path )) { char[] delims = { '=', ',' }; char[] trimchars = { ' ', '"' }; string line = reader.ReadLine(); while ( line != null ) { if ( line.StartsWith( "Project" ) ) { string[] parts = line.Split( delims ); string vsProjectPath = parts[2].Trim(trimchars); if ( VSProject.IsProjectFile( vsProjectPath ) ) project.Add( new VSProject( Path.Combine( solutionDirectory, vsProjectPath ) ) ); } line = reader.ReadLine(); } } } project.IsDirty = false; return project; }
public static void FindProjectReference(Project project, VSProject vsProject, Reference reference) { foreach (Project proj in project.DTE.Solution.Projects) { if (proj.Name.EndsWith(reference.Name)) { vsProject.References.AddProject(proj); return; } if (proj.Kind.Equals(SOLUTION_FOLDER_KIND)) { foreach (ProjectItem subproj in proj.ProjectItems) { if (subproj.Name.EndsWith(reference.Name)) { var pro = (Project) subproj.Object; vsProject.References.AddProject(pro); return; } } } } }
public IList<ProjectReference> GetReferences(VSProject project) { List<ProjectReference> references = new List<ProjectReference>(); foreach (Reference reference in project.References) { ProjectReference projRef = new ProjectReference(); if (reference.SourceProject == null) { projRef.Target = reference.Path; projRef.IsAssembly = true; } else { projRef.Target = reference.SourceProject.Name; projRef.IsAssembly = true; } references.Add(projRef); } return references; }
/// <summary> /// Get <see cref="ProjectMgr"/> as VSProject. /// Can be null. /// </summary> protected VSProject GetProject() { if ((_vsProject == null) && (ProjectMgr != null)) { // get EnvDTE.Project from hierarchy object pVar; ErrorHandler.ThrowOnFailure(ProjectMgr.GetProperty(VSConstants.VSITEMID_ROOT, (int) __VSHPROPID.VSHPROPID_ExtObject, out pVar)); var dteProject = pVar as EnvDTE.Project; if (dteProject == null) return null; // Get VSProject from EnvDTE.Project _vsProject = dteProject.Object as VSProject; } return _vsProject; }
private ProjectTracker(VSProject vsProject) { Contract.Requires(vsProject != null); Contract.Requires(vsProject.Project != null); Contract.Requires(ProjectIsAvailable(vsProject.Project)); //Keep a pointer to our project VS_Project = vsProject; EnvDTE_Project = vsProject.Project; Contract.Assume(EnvDTE_Project.Properties != null); //Get our name ProjectName = EnvDTE_Project.Name; UniqueProjectName = EnvDTE_Project.UniqueName; //Get our host Version frameworkVersion = null; frameworkVersion = GetTargetFramework(EnvDTE_Project); VSServiceProvider.Current.Logger.WriteToLog("fx version: " + frameworkVersion.ToString()); this._host = VSServiceProvider.Current.GetHost(frameworkVersion); //Eagerly add our project's references to the host's lib paths AddProjectReferencesPathsIntoHost(References, Host); //Subscribe to build events VSServiceProvider.Current.BuildBegin += OnBuildBegin; VSServiceProvider.Current.BuildDone += OnBuildDone; //Initialize build variables BuildNumber = 0; InBuild = false; //Get our assembly identity AssemblyIdentity = GetAssemblyIdentity(EnvDTE_Project, Host); //Set the contracts provider _contractsProvider = VSServiceProvider.Current.GetVersionedServicesFactory().CreateContractsProvider(this); }
private static NUnitProject ConvertVSSolution(string path) { NUnitProject project = new NUnitProject(Path.GetFullPath(path)); string solutionDirectory = Path.GetDirectoryName(path); using (StreamReader reader = new StreamReader(path)) { char[] delims = { '=', ',' }; char[] trimchars = { ' ', '"' }; string buildMarker = ".Build.0 ="; Hashtable projectLookup = new Hashtable(); string line = reader.ReadLine(); while (line != null) { if (line.StartsWith("Project(")) { string[] parts = line.Split(delims); string vsProjectPath = parts[2].Trim(trimchars); string vsProjectGuid = parts[3].Trim(trimchars); if (VSProject.IsProjectFile(vsProjectPath)) projectLookup[vsProjectGuid] = new VSProject(Path.Combine(solutionDirectory, vsProjectPath)); } else if (line.IndexOf(buildMarker) >= 0) { line = line.Trim(); int endBrace = line.IndexOf('}'); string vsProjectGuid = line.Substring(0, endBrace + 1); VSProject vsProject = projectLookup[vsProjectGuid] as VSProject; if (vsProject != null) { line = line.Substring(endBrace + 2); int split = line.IndexOf(buildMarker) + 1; string solutionConfig = line.Substring(0, split - 1); int bar = solutionConfig.IndexOf('|'); if (bar >= 0) solutionConfig = solutionConfig.Substring(0, bar); string projectConfig = line.Substring(split + buildMarker.Length); if (vsProject.Configs[projectConfig] == null) { bar = projectConfig.IndexOf('|'); if (bar >= 0) projectConfig = projectConfig.Substring(0, bar); } if (project.Configs[solutionConfig] == null) project.Configs.Add(new ProjectConfig(solutionConfig)); foreach (string assembly in vsProject.Configs[projectConfig].Assemblies) if (!project.Configs[solutionConfig].Assemblies.Contains(assembly)) project.Configs[solutionConfig].Assemblies.Add(assembly); //if (VSProject.IsProjectFile(vsProjectPath)) // project.Add(new VSProject(Path.Combine(solutionDirectory, vsProjectPath))); } } line = reader.ReadLine(); } project.IsDirty = false; return project; } }
private void AddNunitReference(VSProject addedProject) { var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); System.IO.DirectoryInfo programFilesInfo = new DirectoryInfo(programFiles); var nunitDir = programFilesInfo.GetDirectories("NUnit*"); if (nunitDir.Length > 0) { foreach (var dir in nunitDir) { var nunitFilename = Path.Combine(new string[] {dir.FullName, "bin", "net-2.0", "framework", "nunit.framework.dll"}); if (File.Exists(nunitFilename)) { addedProject.References.Add(nunitFilename); return; } } } programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); programFilesInfo = new DirectoryInfo(programFiles); nunitDir = programFilesInfo.GetDirectories("NUnit*"); if (nunitDir.Length > 0) { foreach (var dir in nunitDir) { var nunitFilename = Path.Combine(new string[] { dir.FullName, "bin", "net-2.0", "framework", "nunit.framework.dll" }); if (File.Exists(nunitFilename)) { addedProject.References.Add(nunitFilename); return; } } } }
bool SetupDebuggerOnVS(VSProject vsproject, string acadpath, string startArgs) { bool ret = false; try { //Configuration config =vsproject.Project.ConfigurationManager.Item("Debug", "Any CPU"); //ProjectConfigurationProperties pp =config.Properties as ProjectConfigurationProperties ; //pp.StartProgram = "acad.exe"; //pp.StartWorkingDirectory = ""; vsproject.Project.ConfigurationManager.ActiveConfiguration.Properties.Item("StartProgram").Value = acadpath + "\\acad.exe"; vsproject.Project.ConfigurationManager.ActiveConfiguration.Properties.Item("StartAction").Value = 1; // "Program"; vsproject.Project.ConfigurationManager.ActiveConfiguration.Properties.Item("StartArguments").Value = startArgs; ret = true; } catch { //MessageBox.Show("debug vs error"); } return (ret); }
public void LoadCppProjectWithMacros() { using ( TempResourceFile file = new TempResourceFile(this.GetType(), "resources.CPPLibrary.vcproj", "CPPLibrary.vcproj" )) { VSProject project = new VSProject(file.Path); Assert.AreEqual( "CPPLibrary", project.Name ); Assert.AreEqual( Path.GetFullPath(file.Path), project.ProjectPath); Assert.AreEqual( Path.GetFullPath( @"debug\cpplibrary.dll" ).ToLower(), project.Configs["Debug|Win32"].Assemblies[0].ToString().ToLower()); Assert.AreEqual( Path.GetFullPath( @"release\cpplibrary.dll" ).ToLower(), project.Configs["Release|Win32"].Assemblies[0].ToString().ToLower()); } }
public void NoConfigurations() { WriteInvalidFile( "<VisualStudioProject><CSharp><Build><Settings AssemblyName=\"invalid\" OutputType=\"Library\"></Settings></Build></CSharp></VisualStudioProject>" ); VSProject project = new VSProject( Path.Combine(Path.GetTempPath(),"invalid.csproj" )); Assert.AreEqual( 0, project.Configs.Count ); }
private void AssertCanLoadProject( string resourceName, params string[] configNames ) { string fileName = Path.GetFileNameWithoutExtension( resourceName ); using( TempResourceFile file = new TempResourceFile( this.GetType(), resourceDir + "." + resourceName, resourceName ) ) { VSProject project = new VSProject( file.Path ); Assert.AreEqual( fileName, project.Name ); Assert.AreEqual( Path.GetFullPath( file.Path ), project.ProjectPath ); Assert.AreEqual( fileName.ToLower(), Path.GetFileNameWithoutExtension( project.Configs[0].Assemblies[0].ToString().ToLower() ) ); if ( configNames != null ) { Assert.AreEqual( configNames.Length, project.Configs.Count ); for( int index = 0; index < configNames.Length; index++ ) Assert.AreEqual( configNames[index], project.Configs[index].Name ); } } }
private void AddAssemblyDependency(GenerationEventArgs e, VSProject project, string assemblyName, string assemblyLocation, bool copyLocal) { try { bool hasRef = project.References.Cast<Reference>().Any( r => r != null && string.Equals(r.Name, assemblyName, StringComparison.InvariantCultureIgnoreCase)); if (!hasRef) { Reference dllRef = project.References.Add(assemblyLocation); dllRef.CopyLocal = copyLocal; } } catch (Exception ex) { e.GenerateWarning("Failed to add reference to " + assemblyName + ":" + ex.Message); } }
public void NoConfigurations() { WriteInvalidFile( "<VisualStudioProject><CSharp><Build><Settings AssemblyName=\"invalid\" OutputType=\"Library\"></Settings></Build></CSharp></VisualStudioProject>" ); VSProject project = new VSProject( @"." + System.IO.Path.DirectorySeparatorChar + "invalid.csproj" ); Assert.AreEqual( 0, project.Configs.Count ); }
/// <summary> /// This method determines whether the given type comes from the current project, its temporary assemblies or references. /// </summary> /// <param name="t">The type in question</param> /// <param name="vsProject">The project we planning to add domain service to</param> /// <param name="projectReferences">References collection for the project</param> /// <returns><c>true</c> if the type is visible, <c>false</c> otherwise</returns> private static bool IsVisibleInCurrentProject(Type t, VSProject vsProject, IEnumerable<Reference> projectReferences) { // If we couldn't retirve project or references info -- return true so that the type will appear in the wizard if (t == null || vsProject == null || projectReferences == null) { return true; } Assembly typeAssembly = t.Assembly; string typeAssemblyName = typeAssembly.GetName().Name; Project project = vsProject.Project; // Check if type comes from this project's output assembly string projectAssemblyName = (string)project.Properties.Item("AssemblyName").Value; if (typeAssemblyName.Equals(projectAssemblyName, StringComparison.Ordinal)) { return true; } // Check if type's assembly is located under project's obj directory string relativeObjDirectory = project.ConfigurationManager.ActiveConfiguration.Properties.Item("IntermediatePath").Value as string; string projectObjDirectory = Path.Combine(Path.GetDirectoryName(project.FullName), relativeObjDirectory); if (typeAssembly.Location.StartsWith(projectObjDirectory, StringComparison.OrdinalIgnoreCase)) { return true; } // Check if type comes from one of the project's references foreach (Reference reference in projectReferences) { // If Identity property contains tailing '\0' -- remove it. string referenceName = reference.Identity; if (referenceName.EndsWith(Char.ToString((char)0), StringComparison.Ordinal)) { referenceName = referenceName.Substring(0, referenceName.Length - 1); } if (referenceName.Equals(typeAssemblyName, StringComparison.OrdinalIgnoreCase)) { return true; } } return false; }
private void AddReference(VSProject proj, string path) { try { proj.References.Add(path); } catch { } }
public static VSProject ToProjectItem(this ProjectInstance pi) { var res = new VSProject { FileName = pi.FullPath, ProjectGuid = pi.GetProjectGuid(), GACReferences = pi.GetGACProjectReferences(), LocalReferences = pi.GetLocalLibraryReferences(), ProjectReferences = pi.GetProjectReferences(), OutputFolder = pi.Properties.First(p => p.Name.Equals("OutputPath")).EvaluatedValue }; return res; }
public void ProjectFinishedGenerating(Project project) { this.targetProject = project.Object as VSProject; }
public OpenEngSbWizard(DTE2 visualStudio, VSProject project) { _wizard = new Wizard(visualStudio, project); }
private Reference[] GetReferences(VSProject pVsProj, string pRefName) { List<Reference> result = new List<Reference>(); // See if it has our reference for (int j = 1; j <= pVsProj.References.Count; ++j) { Reference reference = (Reference) pVsProj.References.Item(j); if (reference.Name == pRefName) { result.Add(reference); } } return result.ToArray(); }
public static string GetIntermediatePath(VSProject project) { return Path.Combine(project.Project.Properties.Item( "FullPath").Value.ToString(), project.Project.ConfigurationManager.ActiveConfiguration.Properties.Item( "IntermediatePath").Value.ToString()); }
private void AddAssemblyDependency(GenerationEventArgs e, VSProject project, Assembly assembly) { AddAssemblyDependency(e, project, assembly.GetName().Name, assembly.Location, false); }