none
Project file getting absolute paths RRS feed

  • Question

  • I'm try to use a ProjectItem from the Project file in VS MSBuild and the path I'm getting is incorrect.  It is always pointing the the Project Directory and it never finds System files or mscorlib.  How do I correct this?
    Friday, April 27, 2018 1:53 PM

All replies

  • Hi,

    Welcome to MSDN forum.

    >>I'm try to use a ProjectItem from the Project file in VS MSBuild and the path I'm getting is incorrect.

    What's your project and how did you get the projectitem path in your code?

    You can have a look at here:

    https://msdn.microsoft.com/en-us/library/system.io.path.getfullpath%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 30, 2018 8:25 AM
  •  using Microsoft.Build.Construction;
    using Microsoft.Build.Evaluation;

           Project project = new Project(projectInSolution.RelativePath);

    Tuesday, May 1, 2018 6:09 PM
  • Hi,

    I will move your thread to c# forum to discuss your problem. If you have problems about visual studio IDE, please feel free to let me know.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 3, 2018 1:55 AM
  • That is correct because there is no 1 path to system or mscorlib. It is completely dependent upon the target framework of the project. The items in a project are relative to the root of the project but framework references are just the assembly name. During a build MSBuild uses the ResolveAssemblyReference task to find the correct version of the assembly. This is an expensive call.

    You can find the source for this task here.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, May 3, 2018 2:15 PM
    Moderator
  • Your point of course is the point.  Thx for your help.  However, simply being able to load a Project file doesn't make it usable unless there is a way to access the portion of build which does the resolution without doing a build.  For example in an alternate editor for a language one needs to have access to the symbols.  This requires knowing where to look for the appropriate .PDB or other symbol sources in the system files as well as the project files.
    Thursday, May 3, 2018 6:15 PM
  • Symbols or metadata? They are 2 different things and come from 2 different locations. In the editor the assembly metadata is used to provide intellisense support in combination with any doc file that resides with the assembly. VS pulls this information from a cache when referencing GAC'ed assemblies because the GAC doesn't store the doc files. VS gets the pathing information from the registry. 

    During debugging the CLR loads the assembly using its pathing rules. Once it has located the runtime assembly then the symbol file is found by looking in the symbol cache based upon the runtime binary that was loaded.

    So, I assume you're looking for design time info so you can get access to the metadata? If so then MSBuild is the correct approach via the ResolveAssemblyReference task. That is how, from what I understand, VS does it as well. You can call it in your own code but you're going to have to set everything up correctly and it is very picky. Here's a link to an MSDN blog article on how someone from MS does it. It was written in F# and doesn't work correctly with MSBuild v15 so you'll need to make some adjustments. They are also making some assumptions which you'll have to convert to data from the project file.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, May 3, 2018 8:20 PM
    Moderator
  • Thanks this is helpful.
    Friday, May 4, 2018 12:50 PM
  • This worke3d in part.  The link was in F# but translated to C# easily.  However, it for some reason did not find the .pdb in the project directory bin\debug I had to write that code.  Finally, now that I have the .pdb I find no documentation since vs2010 for gaining access to their contents.  The 2010 c++ won't convert to vs2017, seems some .h files were left out.
    Sunday, May 6, 2018 8:08 PM
  • The standard PDB files can be read using the appropriate Windows calls. Someone wrote a managed wrapper if your interested. However there is a newer portable PDB format being used now that you'd need to support as well if you wanted to read PDB files.

    Michael Taylor http://www.michaeltaylorp3.net

    Sunday, May 6, 2018 8:16 PM
    Moderator