none
How to define a codeBase element depending on the platform (x86/x64) RRS feed

  • Question

  • Hi,

    I have an issue with building/testing a web application where I reference an assembly available in c:\program files on my workstation but in c:\program files (x86) on the build server. This assembly is "Microsoft.VisualStudio.Enterprise.ASPNetHelper" (used a.o. for code coverage).

    Locally, the path is "C:/Program Files/Microsoft Visual Studio 10.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.dll".

    On the Build Server, the path is "C:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.dll".

    As this assembly is not in the GAC, Visual Studio use a codeBase element in the web.config to define the binding

      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.VisualStudio.Enterprise.ASPNetHelper" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <codeBase version="10.0.0.0" href="file:///C:/Program%20Files/Microsoft%20Visual%20Studio%2010.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.DLL"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    

    How could I manage this to make it work both locally and on the Build machine ?


    Valéry Letroye

    Tuesday, April 24, 2012 11:50 AM

Answers

  • It's not straightfoward to use the "Transforms" on the TFS Build Server.

    I thought I would have to customize the Build Template (Actually, I don't publish the websites, but only precompile them).

    • First, to call MSBuild for websites (and websites only) with the adhoc parameters to produce the appropriate web.config (based on the configuration selected for the Build). I cannot just add the parameters as MSBuild Arguments in the Build Definition because they a other projects :/
    • Next, to copy this web.config from obj\<MyConfiguration>ormWebConfig\transformed folder\ into the bin folder.

    But I found I could simply customize the csproj as explained here http://nirajrules.wordpress.com/2011/07/04/integrating-web-config-transformations-with-tfs-build/ to use the "Transforms" without customizing the Build Template... And... it works like a charm !!!

    I really like this solution as it's more "standard/out-of-the-box" that using a post Build Event.

    Valéry Letroye

    Friday, April 27, 2012 9:18 AM
  • Hi, 

    You are seeing compilation error right?  probing paths can be only relative path we cant specify absolute path. 

    Is Transforming web.config based on the server does helps you? how from here  also from here

    Does this helps you?.


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Thursday, April 26, 2012 4:47 PM

All replies

  • Hi, 

    Did you tried of specifying, 

    <codeBase version="10.0.0.0"

    href="<%Program Files%>/Microsoft Visual Studio 10.0/Common7/IDE/PrivateAssemblies

    /Microsoft.VisualStudio.Enterprise.ASPNetHelper.DLL"/>


    this should be resolved, to be honest i didn't tried as I do have 32 bit, so please check.


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Tuesday, April 24, 2012 12:52 PM
  • You may not use environment variables in a config file ?!

    I had a doubt and did test your suggestion. As I was expecting, it fails. The error is: hexadecimal value 0x3C, is an invalid attribute character.

    Did you actually mean that it works for you on your x86 workstation 8| ?


    Valéry Letroye

    Tuesday, April 24, 2012 1:03 PM
  • Hi Valery,

    How about this workaround:

    1. Add a environment variable named ASPNetHelper, and its value is "%Program Files%/Microsoft Visual Studio 10.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.DLL

    2. Try this statements

      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.VisualStudio.Enterprise.ASPNetHelper" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <codeBase version="10.0.0.0" href="${ASPNetHelper}"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 26, 2012 5:41 AM
    Moderator
  • Do you really mean setting a system environment variable on the server and on my machine ? (E.g. Using the "set" dos command line)

    Based on the notation "$(...)", it seems to me that you actually suggest  a "MSBuild variable" (But I don't see how to use MSBuild variable to execute a website ?)... The only notation I know for environment variable is indeed like this: %ProgramFiles%. Maybe could you tell me more about what you mean by an environment variable and where/how to set it ? Also notice that this has to work on all the team developers' workstation, so I would like to avoid a manual update of all those workstation (I.e.: A post build event would fit)

    I did however update the web.config as suggested and did execute in a dos prompt : set ASPNetHelper=%Program Files%/Microsoft Visual Studio 10.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.DLL 

    But as expected based on my knowledge, it doesn't help :/


    Valéry Letroye



    Thursday, April 26, 2012 7:50 AM
  • Hi, 

    You are seeing compilation error right?  probing paths can be only relative path we cant specify absolute path. 

    Is Transforming web.config based on the server does helps you? how from here  also from here

    Does this helps you?.


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Thursday, April 26, 2012 4:47 PM
  • There is no compilation error but an error at runtime because the assembly is not found.

    Codebase hint must have an absolute pathg (http://blogs.msdn.com/b/junfeng/archive/2004/11/16/258081.aspx). And using the codeBase I copied in my first post works fine on my workstation. Using the same codeBase with "program file (x86)" on the server works fine too. In both case, not setting the right codeBase results at runtime (i.e. when opening the website in a browser) in the error "An error occurred during the processing of a configuration file required to service this request: Could not load file or assembly 'Microsoft.VisualStudio.Enterprise.ASPNetHelper, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."

    The two links that you send me are very interesting !! I did already see web.config transformation used by some colleagues' website but didn't realize the actual purpose. I will investigate asap. Otherwise, post build event is the most obvious (and brute) way to achieve my purpose.

    Thx a lot !


    Valéry Letroye

    Friday, April 27, 2012 7:25 AM
  • It's not straightfoward to use the "Transforms" on the TFS Build Server.

    I thought I would have to customize the Build Template (Actually, I don't publish the websites, but only precompile them).

    • First, to call MSBuild for websites (and websites only) with the adhoc parameters to produce the appropriate web.config (based on the configuration selected for the Build). I cannot just add the parameters as MSBuild Arguments in the Build Definition because they a other projects :/
    • Next, to copy this web.config from obj\<MyConfiguration>ormWebConfig\transformed folder\ into the bin folder.

    But I found I could simply customize the csproj as explained here http://nirajrules.wordpress.com/2011/07/04/integrating-web-config-transformations-with-tfs-build/ to use the "Transforms" without customizing the Build Template... And... it works like a charm !!!

    I really like this solution as it's more "standard/out-of-the-box" that using a post Build Event.

    Valéry Letroye

    Friday, April 27, 2012 9:18 AM