{"id":7433,"date":"2004-07-14T13:34:00","date_gmt":"2004-07-14T13:34:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2004\/07\/14\/tips-and-tricks-of-visual-studio-file-and-project-references\/"},"modified":"2024-07-05T15:03:36","modified_gmt":"2024-07-05T22:03:36","slug":"tips-and-tricks-of-visual-studio-file-and-project-references","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/tips-and-tricks-of-visual-studio-file-and-project-references\/","title":{"rendered":"Tips and Tricks of Visual Studio File and Project References"},"content":{"rendered":"<h2><font face=\"Verdana\" size=\"2\"><\/p>\n<h2><font size=\"5\">Tips and Tricks of Visual Studio File and Project References<\/p>\n<p><\/font><\/h2>\n<p class=\"Text\">Cameron McColl, Bill Horst<br \/>Visual Basic Product Team<br \/>Microsoft Corporation<\/p>\n<p class=\"Text\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"Text\">August 2004<\/p>\n<p class=\"Text\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"Text\"><span class=\"Bold\">Summary:<span>&nbsp; <\/span><\/span>This paper describes some of the interesting properties and quirks of the Visual Studio .NET Visual Basic project model. The paper explores what&#8217;s going on, and proposes possible workarounds. ( printed pages)<\/p>\n<p class=\"Text\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"Label\">Applies to:<\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Microsoft Visual Studio .NET 2003<\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Microsoft Visual Studio 2002.<\/p>\n<h4><font size=\"5\">Introduction<\/p>\n<p><\/font><\/h4>\n<p class=\"Text\">Consider having several hundred assemblies that are all consumed by a MAIN project either directly or indirectly. Clearly there is no need to open a solution containing all of these projects. Instead you decide to use file references for any assembly which you are not modifying. This makes managing the solution simpler and improves performance. For assemblies that you do need to modify you add the relevant project to your solution and make project references instead of file references.<\/p>\n<p class=\"Text\">For example, in one particular case, a Visual Studio user had written an extensive macro that automated the creation of the solution along with the correct projects and references.<\/p>\n<h5><font size=\"4\">The Problem: Mixing File and Project References<\/p>\n<p><\/font><\/h5>\n<p class=\"Text\">Suppose you have a solution with the following three projects:<\/p>\n<p class=\"Text\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"Figure\">&nbsp;<img decoding=\"async\" src=\"\"><\/p>\n<p class=\"Label\"><span class=\"LabelEmbedded\"><span>Fi<\/span>gure 1: Sample Solution<\/p>\n<p><\/span><\/p>\n<p class=\"Text\">This configuration causes the following error in Visual Basic if <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">Sub Main<\/font><\/span><\/span> uses the type<span class=\"CodeEmbedded\"><span><font face=\"Courier New\"> X<\/font><\/span><\/span> from Project A:<\/p>\n<p class=\"TextinList1\">Project &#8216;Main&#8217; makes an indirect reference to assembly &#8216;ProjectB&#8217;, which contains &#8216;class2&#8217;. Add a reference to &#8216;ProjectB&#8217; to your project.<\/p>\n<h5><font size=\"4\">The Explanation: Indirect References<\/p>\n<p><\/font><\/h5>\n<p class=\"Text\">Why does this error occur? The key to the problem is mentioned in the error message&ndash;&#8221;indirect reference.&#8221;<\/p>\n<p class=\"Text\">Before considering the definition of an indirect reference, you should be clear on the difference between a file reference and a project reference. <span><\/p>\n<p><\/span><\/p>\n<p class=\"Text\">A f<span class=\"Italic\"><em>ile reference<\/em><\/span> is a reference to the built assembly of a project. In the above figure, the file reference to Project A is actually a reference to the assembly Project A produced as a result of building the project. This assembly is usually located in the project&#8217;s Bin directory.<\/p>\n<p class=\"Text\">A <span class=\"Italic\"><em>project reference<\/em><\/span> is a reference to the actual project. You can think of this as an in-memory representation of the assembly, which is automatically updated as you edit your code. <\/p>\n<p class=\"Text\">So, what is an <span class=\"Italic\"><em>indirect reference<\/em><\/span>? In the example, Project Main calls <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">X.Bar<\/font><\/span><\/span> in its <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">Sub Main<\/font><\/span><\/span>. To compile this code, the compiler needs to resolve the name <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">X<\/font><\/span><\/span>. The definition of <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">X<\/font><\/span><\/span> is found in Project A, which <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">Main<\/font><\/span><\/span> references directly. The compiler must also resolve the name <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">Bar<\/font><\/span><\/span>. Since the type of <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">X <\/font><\/span><\/span>is in Project B the compiler looks to see if it has a reference to Project B. By design, the compiler does not consider a project reference when resolving a type that is defined in a file referenced assembly (such as Project A). Thus the compiler does not see the <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">Main<\/font><\/span><\/span> project reference to Project B. The compiler does know, however, that assembly A references assembly B. Since <span class=\"CodeEmbedded\"><span><font face=\"Courier New\">Main<\/font><\/span><\/span> references A, the compiler sees assembly B as an indirect reference. Thus the compiler reports back that there needs to be a direct reference to Project B for this code to work. This means a File Reference to Project B.<span><\/p>\n<p><\/span><\/p>\n<h5><font size=\"4\">Workarounds<\/p>\n<p><\/font><\/h5>\n<p class=\"Text\">The main problem stems from mixing file and project references within the same solution. These are some of the possible workarounds and the problems you may encounter with these:<\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span class=\"LabelEmbedded\">Always use project references<\/span>&#8211;This implies all projects live in the same solution. However, this workaround becomes hard to manage when dealing with large numbers of projects within a given solution, <span>&nbsp;<\/span>or when some of the projects are built in a language other than Visual Basic, such as C#. A Project Reference to a C# project may look the same as a Project Reference to a Visual Basic project however the C# reference is always <span>&nbsp;<\/span>a File Reference.<\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span class=\"LabelEmbedded\">Always use file references<\/span>&#8211;If you decide to do this, you always add a reference to a project by selecting the dll from the output Bin directory. This is done for each project that is in your solution. For assemblies that you do not include in your solution, you can use a common directory to host these. This works because these assemblies are not changing with successive builds of your solution.<\/p>\n<p class=\"AlertTextinList1\"><span class=\"LabelEmbedded\">Note<\/span>&nbsp;&nbsp;&nbsp;This approach has issues that need to be handled carefully to avoid problems. To understand these problems you must first be familiar with the <span class=\"Bold\">Reference Path<\/span> property of Visual Basic projects. See below for more detail.<\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span class=\"LabelEmbedded\">Build your project outputs to a common Bin directory and use CopyLocal=False&#8211;<\/span>It may seem to make sense to always use file references, but avoid the <span class=\"Bold\">CopyLocal<\/span>=<span class=\"Bold\">True<\/span> problem. In this scenario, all projects in your solution build to a common directory and your reference path for each project is to this same common directory. Unfortunately, there is a known issue with this approach: Assemblies located in this common directory get locked if they exceed 64K in size. Once an assembly is locked by a referencing project, other projects are unable to build against these references. See <span class=\"LinkText\"><span><u>Microsoft Knowledge Base Article &ndash; 313512<\/u><\/span><\/span><span class=\"LinkID\"><span>!href(http:\/\/support.microsoft.com\/default.aspx?scid=kb;en-us;313512)<\/span><\/span> <span>for details on how to make this a <\/span>viable model for your project development. <span><\/p>\n<p><\/span><\/p>\n<h6><font size=\"2\">Understanding the Reference Path property<\/p>\n<p><\/font><\/h6>\n<p class=\"Text\">Suppose you have two projects, Project A and Project B. You decide that Project B requires a reference to Project A, so you navigate to the Bin directory for Project A and select the Project A .dll. If you now view the properties for Project B, notice that the <span class=\"Bold\">Reference Path <\/span>property setting contains an entry that is the full path to the Project A Bin directory<span>.<\/p>\n<p><\/span><\/p>\n<p class=\"Text\">The <span class=\"Bold\">Reference Path<\/span> property tells Visual Studio where to look for referenced assemblies; the default is the path you used when you added the reference. Thus, when you build Project B, Visual Studio takes each path listed in the <span class=\"Bold\">Reference Path<\/span> property and looks to see if it contains the assembly being sought. In this example, Visual Studio is looking for the Project A.dll. If the assembly is not found, Visual Studio looks at the next <span class=\"Bold\">Reference Path<\/span> setting, and so on. If the assembly is found, Visual Studio copies the assembly from the found location into the Bin directory of the project being built. This is what the <span class=\"Bold\">CopyLocal=True<\/span> property means. This ensures that you always have the latest copy of the assembly at runtime.<\/p>\n<p class=\"Text\">So, Visual Studio uses the <span class=\"Bold\">Reference Path<\/span> property during compilation; it should not be confused by the algorithm used to locate an assembly at run time.<\/p>\n<p class=\"Text\">Sounds good so far, so where do the problems start? Suppose that in addition to your Projects A and B, there are also a number of additional assemblies that Project A references but you do not have as projects in your solution. For example, you might place the latest version of all your assemblies in a common directory. You now decide that Project B needs to add a reference to Assembly X in your common directory. When you add the reference you are presented with the following message box:<\/p>\n<p class=\"Text\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"Figure\"><img decoding=\"async\" src=\"\"><\/p>\n<p class=\"Label\"><span class=\"LabelEmbedded\"><span>Figure 2: Message box reporting problem.<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"Text\">What is going on here? When you add this reference Visual Studio attempts to add the directory c:common (your common assembly directory) to the reference path for this project. When it does this, the path is placed at the beginning of the reference path ordering. Visual Studio uses this ordering to locate an assembly at compile time. If the common directory contains an assembly that was previously being picked up by a path further down the reference path list, Visual Studio now picks this assembly from the common directory instead of the previous location. The dialog box is simply warning you of this change.<\/p>\n<p class=\"Text\">So, when you see this message box what do you do? If you click No, your reference is not added, clearly not what you wanted. If you click Yes, your reference is added but there are side effects. In this particular scenario the side effect is quite serious. The Project B reference to Project A was previously being copied from the Project A Bin directory, but Visual Studio now takes it from the common directory. This is bad because changes you make to Project A code are not now reflected in Project B. This is because the copy of the Project A .dll in the common directory is not updated when you build Project A.<\/p>\n<p class=\"Text\">To remedy this, make sure that your <span class=\"Bold\">Reference Path <\/span>settings are in the correct order to achieve the desired effect. In this particular scenario, where you have a common directory for assemblies that are not included as projects in the current solution, place the common directory as the last entry in the <span class=\"Bold\">Reference Path<\/span> property settings to get the correct behavior. <\/p>\n<h6><font size=\"2\">Macro Solution<\/p>\n<p><\/font><\/h6>\n<p class=\"Text\">Of course, doing this every time you change a project reference is time consuming and tedious. You may find the following macro a useful way to keep your reference path value correct. <\/p>\n<p class=\"AlertText\"><span class=\"LabelEmbedded\">Note<\/span>&nbsp;&nbsp;&nbsp; Using this macro is only advised when conditions are as follows:<\/p>\n<p class=\"NumberedList2\"><span><span>1.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>You always use file references even if the assembly is build by a project currently in your solution.<\/p>\n<p class=\"NumberedList2\"><span><span>2.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>If an assembly is being built by a project in your solution, any references to this assembly should be made from the project&rsquo;s bin directory.<\/p>\n<p class=\"NumberedList2\"><span><span>3.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>All assemblies not being built by projects in your solution should be located in a common assembly directory and all references to these assemblies should be made from this directory.<\/p>\n<p class=\"AlertTextinList1\">If these conditions are being met the macro updates the reference path property for each project in your solution and modifies it to ensure that the original problem described in this paper does not occur.<\/p>\n<p class=\"Text\">Run this macro after adding or removing references in the projects of your solution. It has the following assumptions:<\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>There are no references to assemblies in the bin directories of projects not included in this solution.<span><\/p>\n<p><\/span><\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>A .dll (dynamic-link library) file is only present in a project&#8217;s bin directory if it is referenced by the project.<span><\/p>\n<p><\/span><\/p>\n<p class=\"BulletedList1\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>No two projects in the solution have the same name, and that no project references an assembly outside the solution with the same name as a project inside the solution.<\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileReferenceMacro<span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; Author:&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;William Horst [WHorst@Microsoft.com]<span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; Purpose:&nbsp; The purpose of this macro is to avoid problems that can <\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; occur with mismatched symbols when combining project and file <\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; references. The code walks through all the projects in the currently <\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; opened solution and replaces all references with file references.&nbsp;<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; It then updates the reference paths so that all project bin <\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; directories are checked before any other folders, and <span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">&#8216; that a project&#8217;s bin directory is checked before any other path with &#8216; its assembly present.<span><\/p>\n<p><\/span><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\">Imports EnvDTE<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">Imports System.Diagnostics<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">Imports System.IO<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">Imports System.Collections<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\">Imports System.Collections.Specialized<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\">Public Module FileReferenceMacro<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp; <\/span>&#8216; This is the name of the log file.<span>&nbsp; <\/span>It will be stored in the C<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp; <\/span>&#8216; directory.<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp; <\/span>Const LogFileName As String = &#8220;ProjectRef.lst&#8221;<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp; <\/span>&#8216; Purpose: This is the main method of the macro and carries out the <\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp; <\/span>&#8216; behavior described above.<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp; <\/span>Sub SetFileRefsForDevelopment()<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Dim logPath As String = &#8220;C:&#8221; &amp; LogFileName<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Dim FileOut As StreamWriter<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Dim Name As String<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Dim proj As EnvDTE.Project<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Dim Projects As SortedList<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Dim refproj As EnvDTE.Project<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Dim vsproject As VSLangProj.VSProject<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>FileOut = New StreamWriter(logPath)<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8216; Create collection of all project names <\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Projects = New SortedList<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>For index As Integer = 1 To DTE.Solution.Projects.Count<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>proj = DTE.Solution.Projects.Item(index)<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>If proj.UniqueName &lt;&gt; EnvDTE.Constants.vsMiscFilesProjectUniqueName Then<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Projects.Add(proj.Name, index)<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>End If<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Next index<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8216; Iterate through all projects in the solution.<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>For Each proj In DTE.Solution<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>FileOut.WriteLine(&#8220;* * * * * * * * * * * * * * * * * * * * * * *&#8221;)<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>FileOut.WriteLine(&#8220;Processing project &#8221; &amp; proj.Name)<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;<\/span>vsproject = CType(proj.Object, VSLangProj.VSProject)<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8216; Don&#8217;t try to process the special project for misc files.<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>If proj.UniqueName &lt;&gt; EnvDTE.Constants.vsMiscFilesProjectUniqueName Then<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8216; Change all references to file references.<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>For Each ref As VSLangProj.Reference In vsproject.References<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name = ref.Name<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8216; If in solution:<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>If Projects.ContainsKey(Name) Then<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>refproj = ref.SourceProject<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8216; If Not Project reference:<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>If refproj Is Nothing Then<\/p>\n<p><\/font><\/p>\n<p class=\"Code\">\n<p><font face=\"Courier New\">&nbsp;<\/font><\/p>\n<\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8216; Grab project.<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>For Each project As EnvDTE.Project In DTE.Solution<\/p>\n<p><\/font><\/p>\n<p class=\"Code\"><font face=\"Courier New\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>If project.Name = ref.Name Then<\/p>\n<p><\/font><\/p>\n<\/p>\n<p><\/font><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Tips and Tricks of Visual Studio File and Project References Cameron McColl, Bill HorstVisual Basic Product TeamMicrosoft Corporation &nbsp; August 2004 &nbsp; Summary:&nbsp; This paper describes some of the interesting properties and quirks of the Visual Studio .NET Visual Basic project model. The paper explores what&#8217;s going on, and proposes possible workarounds. ( printed pages) [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[192,195],"tags":[119],"class_list":["post-7433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-featured","category-visual-basic","tag-pages"],"acf":[],"blog_post_summary":"<p>Tips and Tricks of Visual Studio File and Project References Cameron McColl, Bill HorstVisual Basic Product TeamMicrosoft Corporation &nbsp; August 2004 &nbsp; Summary:&nbsp; This paper describes some of the interesting properties and quirks of the Visual Studio .NET Visual Basic project model. The paper explores what&#8217;s going on, and proposes possible workarounds. ( printed pages) [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/7433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=7433"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/7433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=7433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=7433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=7433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}