locked
DeploymentItem does not work with VS 2010 when setting xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" in the app.config RRS feed

  • Question

  • Hello,

    I have converted a lot of unit test projects from VS 2008 to VS 2010. After the conversion, they have all been manually reconfigured to target .Net v3.5 instead of v4.0.

    Many unit tests use a database which is dropped in the 'out' folder (in order to be auto-attached) using the test attribute "DeploymentItem". The local database file is correctly marked as "Content" and "Copy Always" in the Solution Explorer and "Deployment" is enabled in the testrunconfig file.

    However, after the conversion, I notice that unit tests of some test projects are working fine while those of other test projects fail. It appears that they fail because the database file is not deployed.

    After investigation, I found that the only difference between the test projects with succeeding tests and failing tests is in the app.config.

    The DeploymentItem attribute has no effect if the app.config contains the default namespace xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" on the section <configuration>.

     

    <?xml version="1.0"?>

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

      <startup>

        <supportedRuntime version="v2.0.50727"/>

      </startup>

    </configuration>

     

    Here is a solution with two test projects reproducing the problem (one succeeds, the other fails) : DeploymentAttributev35  The only difference between the two projects is in the app.config.

    Is there anyone who could explain why the attribute "DeploymentItem" is not taken into account when the xmlns is set on the version 2.0 ? Is this a bug or a "feature" ?

    Next, I really need to target v3.5 in my unit tests. If I remove this xmlns, am I still testing my projects 100% against v3.5 ? FYI: my projects are part of an enterprise framework foundation used by business application running on .Net v3.5.

     

    Thx a lot in advance for any opinion you could share on this.

    V.




    Tuesday, April 19, 2011 8:16 AM

All replies

  • Hello Varlery,

    For the first question, DeployementAttribute is a attribute.

    This attribute can be specified on a test method. There can be multiple instances of this attribute to specify more than one item. The item path can be absolute or relative. Relative paths are relative to the RelativePathRoot setting found in the .testrunconfig file.

    The following examples demonstrate different usage of the DeploymentItemAttribute:

    ·         <tt>[DeploymentItem("file1.xml")]</tt> Deploys an item named file1.xml located at the RelativeRootPath. The file is deployed to the deployment root directory.

    ·         <tt>[DeploymentItem("file2.xml", "DataFiles")]</tt> Deploys an item named file2.xml located at the RelativeRootPath. The file is deployed to the DataFiles subdirectory of the deployment root directory.

    ·         <tt>[DeploymentItem("C:\\MyDataFiles\\")]</tt> Deploys all items and directories found within the MyDataFiles directory. This does not create the MyDataFiles directory underneath the deployment directory. All files and directories within MyDataFiles will be deployed to the deployment root directory. To copy the entire MyDataFiles directory structure, you must specify MyDataFiles as an output directory.

    ·         <tt>[DeploymentItem("%myDir%\myFile.txt")]</tt> Deploys the file myFile.txt if that file exists in the directory to which %myDir% resolves.  

    For the second question, you can refer to the website: http://msdn.microsoft.com/zh-cn/library/gg601487.aspx , it describe how to configure your Unit test to Target .NET Framework 3.5.

    Have a nice day,

    SmallClothTiger

    Wednesday, April 20, 2011 2:56 AM
  • Thanks,

     

    Unfortunatelly, nothing in there explaining why xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" prevents the DeploymentItemAttribute to be "executed" with a test project "2010" targeting .Net v3.5 while it works fine with a test project "2008"... This is just a namespace specifying the schema to be used to validate the configuration file. I don't see how this could impact the behavior of the DeploymentItemAttribute.

    Except that I found this xmlns is only documented in the context of ASP.Net: http://msdn.microsoft.com/en-us/library/ms228147.aspx. And VS 2010 SP1 only supports test projects targeting .Net v3.5 in the default host adapter and not in the ASP.Net host  ?!? Maybe this is the explanation ??? Really weird however IMO.

     

    Wednesday, April 20, 2011 7:11 AM