Datei: NDOPackage/ProjectExtensions.cs

Last Commit (33e9857)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1 using System;
2 using System.IO;
3 using Microsoft.VisualStudio.Shell.Interop;
4
5 namespace NDOVsPackage
6 {
7 ····internal static class ProjectExtensions
8 ····{
9 ········public static EnvDTE.Project DteProject( this Project project )
10 ········{
11 ············ThreadHelper.ThrowIfNotOnUIThread();
12
13 ············var projects = ApplicationObject.VisualStudioApplication.Solution.Projects;
14 ············EnvDTE.Project dteProj = null;
15 ············foreach (EnvDTE.Project proj in projects)
16 ············{
17 ················if (proj.Name == project.Name)
18 ················{
19 ····················dteProj = proj;
20 ····················break;
21 ················}
22 ············}
23
24 ············return dteProj;
25 ········}
26
27 ········public static string DefaultMappingFileName( this Project project )
28 ········{
29 ············return Path.Combine( Path.GetDirectoryName(project.FullPath), "NDOMapping.xml" );
30 ········}
31
32
33 ········public static string MappingFilePath( this Project project )
34 ········{
35 ············string defaultFileName = project.DefaultMappingFileName();
36 ············if (File.Exists( defaultFileName ))
37 ················return defaultFileName;
38 ············ThreadHelper.ThrowIfNotOnUIThread();
39 ············var assemblyName = project.DteProject().Properties.Item( "AssemblyName" ).Value;
40 ············if (assemblyName == null)
41 ················return null;
42 ············string mappingFile = Path.Combine( project.FullPath, assemblyName + "ndo.xml" );
43 ············if (File.Exists( mappingFile ))
44 ················return mappingFile;
45 ············return null;
46 ········}
47
48
49 ········public static string DefaultMappingFileName( this EnvDTE.Project project )
50 ········{
51 ············ThreadHelper.ThrowIfNotOnUIThread();
52 ············return Path.Combine( Path.GetDirectoryName( project.FullName ), "NDOMapping.xml" );
53 ········}
54
55
56 ········public static string MappingFilePath( this EnvDTE.Project project )
57 ········{
58 ············string defaultFileName = project.DefaultMappingFileName();
59 ············if (File.Exists( defaultFileName ))
60 ················return defaultFileName;
61 ············ThreadHelper.ThrowIfNotOnUIThread();
62 ············var assemblyName = project.Properties.Item( "AssemblyName" ).Value;
63 ············if (assemblyName == null)
64 ················return null;
65 ············string mappingFile = Path.Combine( project.FullName, assemblyName + "ndo.xml" );
66 ············if (File.Exists( mappingFile ))
67 ················return mappingFile;
68 ············return null;
69 ········}
70
71
72 ········public static bool MappingFileExists(this Project project )
73 ········{
 
74 ············return project.MappingFilePath() != null;
75 ········}
76
77 ········public static IVsHierarchy GetVsHierarchy( this EnvDTE.Project project )
78 ········{
79 ············ThreadHelper.ThrowIfNotOnUIThread();
80 ············IVsHierarchy projectHierarchy = null;
81
82 ············( (IVsSolution) Package.GetGlobalService( typeof( IVsSolution ) ) ).GetProjectOfUniqueName( project.UniqueName, out projectHierarchy );
83 ············return projectHierarchy;
84 ········}
85
86
87 ········public static IVsHierarchy GetVsHierarchy( this Project project )
88 ········{
89 ············IVsHierarchy projectHierarchy;
90 ············project.GetItemInfo( out projectHierarchy, out _, out _ );
91
92 ············return projectHierarchy;
93 ········}
94 ····}
95 }
96
New Commit (aa458ff)
1 //
2 // Copyright (c) 2002-2022 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.IO;
25 using Microsoft.VisualStudio.Shell.Interop;
26
27 namespace NDOVsPackage
28 {
29 ····internal static class ProjectExtensions
30 ····{
31 ········public static EnvDTE.Project DteProject( this Project project )
32 ········{
33 ············ThreadHelper.ThrowIfNotOnUIThread();
34
35 ············var projects = ApplicationObject.VisualStudioApplication.Solution.Projects;
36 ············EnvDTE.Project dteProj = null;
37 ············foreach (EnvDTE.Project proj in projects)
38 ············{
39 ················if (proj.Name == project.Name)
40 ················{
41 ····················dteProj = proj;
42 ····················break;
43 ················}
44 ············}
45
46 ············return dteProj;
47 ········}
48
49 ········public static string DefaultMappingFileName( this Project project )
50 ········{
51 ············return Path.Combine( Path.GetDirectoryName(project.FullPath), "NDOMapping.xml" );
52 ········}
53
54
55 ········public static string MappingFilePath( this Project project )
56 ········{
57 ············string defaultFileName = project.DefaultMappingFileName();
58 ············if (File.Exists( defaultFileName ))
59 ················return defaultFileName;
60 ············ThreadHelper.ThrowIfNotOnUIThread();
61 ············var assemblyName = project.DteProject().Properties.Item( "AssemblyName" ).Value;
62 ············if (assemblyName == null)
63 ················return null;
64 ············string mappingFile = Path.Combine( project.FullPath, assemblyName + "ndo.xml" );
65 ············if (File.Exists( mappingFile ))
66 ················return mappingFile;
67 ············return null;
68 ········}
69
70
71 ········public static string DefaultMappingFileName( this EnvDTE.Project project )
72 ········{
73 ············ThreadHelper.ThrowIfNotOnUIThread();
74 ············return Path.Combine( Path.GetDirectoryName( project.FullName ), "NDOMapping.xml" );
75 ········}
76
77
78 ········public static string MappingFilePath( this EnvDTE.Project project )
79 ········{
80 ············string defaultFileName = project.DefaultMappingFileName();
81 ············if (File.Exists( defaultFileName ))
82 ················return defaultFileName;
83 ············ThreadHelper.ThrowIfNotOnUIThread();
84 ············var assemblyName = project.Properties.Item( "AssemblyName" ).Value;
85 ············if (assemblyName == null)
86 ················return null;
87 ············string mappingFile = Path.Combine( project.FullName, assemblyName + "ndo.xml" );
88 ············if (File.Exists( mappingFile ))
89 ················return mappingFile;
90 ············return null;
91 ········}
92
93
94 ········public static bool MappingFileExists(this Project project )
95 ········{
96 ············ThreadHelper.ThrowIfNotOnUIThread();
97 ············return project.MappingFilePath() != null;
98 ········}
99
100 ········public static IVsHierarchy GetVsHierarchy( this EnvDTE.Project project )
101 ········{
102 ············ThreadHelper.ThrowIfNotOnUIThread();
103 ············IVsHierarchy projectHierarchy = null;
104
105 ············( (IVsSolution) Package.GetGlobalService( typeof( IVsSolution ) ) ).GetProjectOfUniqueName( project.UniqueName, out projectHierarchy );
106 ············return projectHierarchy;
107 ········}
108
109
110 ········public static IVsHierarchy GetVsHierarchy( this Project project )
111 ········{
112 ············IVsHierarchy projectHierarchy;
113 ············project.GetItemInfo( out projectHierarchy, out _, out _ );
114
115 ············return projectHierarchy;
116 ········}
117 ····}
118 }
119