locked
Setting an environment variable in Reference Paths RRS feed

  • Question

  • Hi everyone,

    How do I set the reference path of a C# project with an environment variable?
    I tried using $(MYENVVARIABLE) but it says "Folder path does not exist."

    Regards,

    Jean Grey
    Thursday, December 17, 2009 9:28 AM

Answers

  • Hi,

    Reference Path is use for reference the assembly not located in your project directory and it does need a absolute path to the target assemby.

    If you use trying to use an evironment variable's key here, then I have to say it's wrong place to do this.

    For reference:
    http://msdn.microsoft.com/en-us/library/6taasyc6.aspx

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Wednesday, December 23, 2009 3:39 AM
    Tuesday, December 22, 2009 8:13 AM

All replies

  • Use Environment.GetEnvironmentVariables Method
    With best regards, Yasser Zamani
    Thursday, December 17, 2009 1:16 PM
  • Yes I have this same problem.  Yasser, I do not think he is talking about programmatically setting them.  If you click Project->Properties on the task bar, then click Reference Paths, (you can not use environment variables in each path).  This is a problem because there is no apparent way to have different locations between machines for references, so a project will always will be out of synch between machines with different setups.  It would be nice to be able to use them here because some machines have different directory structures (namely 32bit vs 64bit.... with the whole (Program Files) (Program Files(x86))) structuring.  Anyone know how this can be done? 
    Thursday, December 17, 2009 8:18 PM
  • Hi everyone,

    How do I set the reference path of a C# project with an environment variable?
    I tried using $(MYENVVARIABLE) but it says "Folder path does not exist."

    Regards,

    Jean Grey

    For setting environment variable, use "SetEnvironmentVariable()" function as shown below:

    System.

    Environment.SetEnvironmentVariable("","");


    Balaji Baskar [Please mark the post as answer if it answers your question]
    Thursday, December 17, 2009 8:53 PM
  • Environment.SpecialFolder.ProgramFiles should help you with the different naming structures.
    Thursday, December 17, 2009 9:01 PM
  • Yes, Jeff. You got my question right.

    Guys, sorry but I don't need to use the environment variable inside my code.

    I need it in the project settings, so I can access my dll at the specified path.

    The equivalent of this in C++ project is when you go to:

    Project->Properties->Configuration Properties->Linker->General->Additional Library Directories

    I really can't find an answer to this anywhere else.
    Friday, December 18, 2009 1:23 AM
  • Hi,

    Reference Path is use for reference the assembly not located in your project directory and it does need a absolute path to the target assemby.

    If you use trying to use an evironment variable's key here, then I have to say it's wrong place to do this.

    For reference:
    http://msdn.microsoft.com/en-us/library/6taasyc6.aspx

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Wednesday, December 23, 2009 3:39 AM
    Tuesday, December 22, 2009 8:13 AM
  • Jean,
    Apparently you can edit the .csproj file, modifying the <HintPath> elements that contain paths.  For instance, in my .csproj file I have:

    <HintPath>C:\somepath\my_dll.dll</HintPath>

    changed to:

    <HintPath>$(MY_ENVIROMENT_VARIABLE)\my_dll.dll</HintPath>

    I then removed the reference paths in the UI.  You may have to experiment to get it to work. 

    http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/4dc1451c-694a-4093-afa9-31d6ab57c63b

    Monday, December 28, 2009 2:37 PM
  • You can set a series of paths in the project.csproj.user file by simply specifying you environment variable like this:

    <Project xmlns="http address removed because site wont let me post one">
      <PropertyGroup>
        <ReferencePath>$(LIBS)</ReferencePath>
      </PropertyGroup>
    </Project>

    Or you used to.  Works a treat in VS2005 / VS2008 but doesnt seem to work in VS2010.  This is what I'm currently stuck with.  Anyone know why this no longer works?

    Monday, December 9, 2013 8:01 AM