locked
platform dependent references RRS feed

  • Question

  • I need to reference different versions of some assemblies depending on if I'm building an x86 or an x64 executable. At present, I delete the 32 bit assemblies and add the 64 bit ones. Is there a way to make this happen automatically?
    • Moved by Figo Fei Friday, July 30, 2010 3:28 AM (From:Visual C# General)
    • Moved by Nancy Shao Friday, July 30, 2010 5:44 AM msbuild question (From:Visual Studio Extensibility)
    Thursday, July 29, 2010 9:43 PM

Answers

  • Hi SRing,

    It works fine in C++/CLI projects in my side. I add following in .vcxproj file:

     <ItemGroup>
      <Reference Include="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Condition="'$(Configuration)'=='Release'" >
       <HintPath>..\..\MyAssemblyPath\MyAssembly.dll</HintPath>
      </Reference>
      <Reference Include="System" />
      <Reference Include="System.Data" />
      <Reference Include="System.Xml" />
     </ItemGroup>
    

    And save it. If I change Configuration in Visual Studio, I will close this solution and open it again, the dll will be loaded depending on Configuration settings. Please let me know if there is anything different from you.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    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 SRing Wednesday, August 18, 2010 7:54 PM
    Monday, August 16, 2010 9:22 AM

All replies

  • Hi SRing,

    If you want runtime redirecting you can utilize the app.config settings.

    But it sounds you want VS facilitate it, I moved to VSX forum for better response.

    Thanks.


    Figo Fei
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, July 30, 2010 3:28 AM
  • Hello,

    You can do it by modifing your project file. To open your project file, you can right-click project node, and choose Unload Project, and then right-click project node again, and choose Edit MyProj.csproj. And you also can open it in project directory.

    After opening it, You will see <Reference> and <ProjectReference> items, <Refenerece> item is to include the assembly which is registerd in GAC. <ProjectReference> item is to include the project reference to this project. So you can add condition property in these two items, so that you can include corresponding assembies according to Platform setting. For example:

      <Reference Include="System.Xml" Condition=" '$(Platform)' == 'x86'" />  
    
     <ProjectReference Include="..\ClassLibrary\ClassLibrary.csproj" Condition="'$(Platform)' == 'x64'">
       <Project>{89798266-B6B9-4E3F-8368-562077F19205}</Project>
       <Name>ClassLibrary1</Name>
      </ProjectReference>
    

    If I misunderstood you, or you have any comments, please feel free to let me know.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    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.
    Friday, July 30, 2010 6:17 AM
  • In my c# project one of the assemblies in question is listed as

    <Reference Include="SinapsXNet, Version=1.0.3755.28847, Culture=neutral, PublicKeyToken=04b2a01e84073963, processorArchitecture=x86"> <SpecificVersion>False</SpecificVersion> <HintPath>P:\projects\SinapsXNet 5.4\Release\SinapsXNet.dll</HintPath> </Reference>

    And is contained in ItemGroup. From your example, it's not clear to me how I would put in a condition that would have this point to a different version. If it's not something that gets automatically updated, can I not specify version or publicKeyToken etc.? Also, the dll's in question are not in the gac.

    Friday, July 30, 2010 7:03 PM
  • Hello,

    For example, if you want to include SinapsXNet assmebly when the platform is x86, please refer to code:

    <Reference Include="SinapsXNet, Version=1.0.3755.28847, Culture=neutral, PublicKeyToken=04b2a01e84073963, processorArchitecture=x86" Condition=" '$(Platform)' == 'x86'" /> 
    <SpecificVersion>False</SpecificVersion> 
    <HintPath>P:\projects\SinapsXNet 5.4\Release\SinapsXNet.dll</HintPath>
    </Reference>
    
    
    

    You don't need to sepcify version if you don't want to add specify verison in your application.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com
     


    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.
    Monday, August 2, 2010 9:07 AM
  • This seems to be working fine in my c# projects. If I try the same thing with a c++ vcxproj file, I have problems. Then the reference doesn't show up in the list of references and the project can no longer see the name space. Is there another step in a c++ project?
    Monday, August 2, 2010 3:56 PM
  • Hello SRing,

    Do you mean the Stardard libraries of Visual C++? It has been included in Project Properties > Configuration Properties > VC++ Directories > Library Directories, and they are all 32-bit libraries, so we don't need to conditionally include these libraries to your project. If you want to include other libraries, you can use <ProjectReference> tag in .vcxproj file.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com
     


    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.
    Tuesday, August 3, 2010 5:09 AM
  • No, I meant a Reference Include for a c++/CLR project. If I make the same change that you suggested to reference my sinapsXNet dll in the .vcxproj file, I have problems. SinapsxNet then doesn't show up at all if I look at the project->properties->Common Properties->Framework and References. And, if I try to build the project anyway, the sinapsxnet namespace is no longer known.

    The use of the platform condition for a reference include works fine in my c# projects. Both versions of the dll show up in my project references. But, for some reason, the equivalent change in a vcxproj file doesn't work. Is there another change that's needed too?

    Tuesday, August 3, 2010 3:59 PM
  • Hello SRing,

    It's different between VC++ and C#. If you want to conditionally include a dll into C++/CLR project depending on Platform setting, you can use Preprocessor Macro in source file. For example:

    #ifdef WIN32
    #include "MyDll.h"
    #endif

    If you want to include one assembly but different version, you can use #pragma, For example:

    #ifdef WIN32
    #include "MyDll.h"#pragma comment(linker,"/manifestdependency:\"type='win32' name='MyDll' version='2.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #pragma comment(lib,"MyDll.lib")

    #endif

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com
     


    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.
    Sunday, August 8, 2010 2:18 PM
  • Hello SRing,

    I am writing to follow up this issue. Please let me know what I can help. Thanks.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    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.
    Wednesday, August 11, 2010 6:21 AM
  • I don't know how I would make this work, since I don't include any .h files. I just have the assembly in my list of references. When I want to create something from it, I have code like

    dddd = gcnew SinapsXNet::whatever()

    I don't have a .h to include, so I don't know how a pragma would change things. I take it that there is no way, in c++, to have a platform dependent reference?

    Wednesday, August 11, 2010 3:31 PM
  • Hello,

    Sorry for misunderstanding you.

     I have problems. SinapsxNet then doesn't show up at all if I look at the project->properties->Common Properties->Framework and References.

    I think it's because you don't reload your project file when you change Platform settings. Please try to reload your project file or close your solution and reopen again to see if it works fine.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    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.
    Thursday, August 12, 2010 8:33 AM
  • When I reopen the project, it's still not fine. After I put in the condition, when I reload the project, no reference shows up at all.
    Friday, August 13, 2010 9:40 PM
  • Hi SRing,

    It works fine in C++/CLI projects in my side. I add following in .vcxproj file:

     <ItemGroup>
      <Reference Include="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Condition="'$(Configuration)'=='Release'" >
       <HintPath>..\..\MyAssemblyPath\MyAssembly.dll</HintPath>
      </Reference>
      <Reference Include="System" />
      <Reference Include="System.Data" />
      <Reference Include="System.Xml" />
     </ItemGroup>
    

    And save it. If I change Configuration in Visual Studio, I will close this solution and open it again, the dll will be loaded depending on Configuration settings. Please let me know if there is anything different from you.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    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 SRing Wednesday, August 18, 2010 7:54 PM
    Monday, August 16, 2010 9:22 AM
  • This is working now. I'm not sure what I did wrong before. I hope this gets easier to do in future versions of vs. Thanks
    Wednesday, August 18, 2010 7:54 PM