locked
How to get import custom tasks more than once without warning message? RRS feed

  • Question

  • I'm using some custom tasks from MSBuild Extension Pack (MEP). My projects are splitted among many files. In those files I import the MEP tasks using <import Project="..." /> (twice or three times in two/three files). I receive the warning message when doing this like:

    > ... warning MSB4011: "C:\Program
    > Files\MSBuild\ExtensionPack\MSBuild.ExtensionPack.tasks"
    > cannot be imported again. It was
    > already imported at
    > "D:\...\Tasker.proj (5,3)". This is
    > most likely a build authoring error.
    > This subsequent import will be
    > ignored.

    Does anyone know how to get rid of this warning message? Please help!
    Tuesday, March 30, 2010 12:09 PM

Answers

  • Hi,

     

    We do something similar in our set of scripts. For instsance we have a "tasks.targets" script that declares a property just to be able to tell if the script has been imported or not. Here's what's in the tasks.targets file:

     

      <PropertyGroup>
        <TasksTargetsImported>true</TasksTargetsImported>
      </PropertyGroup>
    

     

    And here's what the importer do:

      <Import Project="Tasks.targets" Condition=" '$(TasksTargetsImported)' == '' "/>
    
    Of course, if the imported file is something you don't "own" you need to find something else that is specifically declared in the file. 

     

     


    fredrikt
    • Marked as answer by Nam Gi VU Thursday, April 1, 2010 7:56 AM
    Thursday, April 1, 2010 7:43 AM

All replies

  • Hello,

    Verify in the "D:\...\Tasker.proj (5,3)" that you don't have this line 2 times !! and remove it ,

    Houssam

     

     

    Tuesday, March 30, 2010 12:20 PM
  • You need to structure your files appropriately. See this post for guidance: http://social.msdn.microsoft.com/forums/en-US/msbuild/thread/57a2447a-42aa-422a-ad61-26662f2305e7

     

    Mike


    Visual Studio ALM MVP
    My Blog | MSBuild Extension Pack | MSBuild Explorer
    Tuesday, March 30, 2010 12:37 PM
  • The best way is to write the script in better way using conditions and/or Choose element. Import only if its not already imported.

    <Import Project=.... Condition="...." />

    • Proposed as answer by Maheep Saraf Wednesday, March 31, 2010 12:35 PM
    • Unproposed as answer by Mike Fourie [MVP] Thursday, April 1, 2010 8:53 AM
    Wednesday, March 31, 2010 12:35 PM
  • Maheep

    I'm not aware of of a way to apply a condition to an import that equates to it not being imported already. Can you elaborate.

    Mike


    Visual Studio ALM MVP
    My Blog | MSBuild Extension Pack | MSBuild Explorer
    Wednesday, March 31, 2010 2:13 PM
  • Maheep

    I'm not aware of of a way to apply a condition to an import that equates to it not being imported already. Can you elaborate.

    Mike


    Visual Studio ALM MVP
    My Blog | MSBuild Extension Pack | MSBuild Explorer
    Wednesday, March 31, 2010 2:13 PM
  • Hello, Maheep

    Could you elaborate how to get the condition that equate to it not being imported already As Mike asked? 

    Please let us know.

    Thanks

    Chao

    Thursday, April 1, 2010 3:12 AM
  • Hi,

     

    We do something similar in our set of scripts. For instsance we have a "tasks.targets" script that declares a property just to be able to tell if the script has been imported or not. Here's what's in the tasks.targets file:

     

      <PropertyGroup>
        <TasksTargetsImported>true</TasksTargetsImported>
      </PropertyGroup>
    

     

    And here's what the importer do:

      <Import Project="Tasks.targets" Condition=" '$(TasksTargetsImported)' == '' "/>
    
    Of course, if the imported file is something you don't "own" you need to find something else that is specifically declared in the file. 

     

     


    fredrikt
    • Marked as answer by Nam Gi VU Thursday, April 1, 2010 7:56 AM
    Thursday, April 1, 2010 7:43 AM
  • Yes. This is what I had used in my project too. Was Away for weekend so couldn't answer. :)

    In our case there due to some odd reasons the same target name was used for two different targets in two seperate files. So in both the scripts we had defined the property as fredrikt has suggested and in importer script we used the choose element like this

    <Choose>
          <When Condition="'$(TasksTargetsImported)' == '' " >
                <Import Project="Something" />
          </When>
          <Otherwise>

                <Import Project = "SomethingElse"/>
          </Otherwise>
    </Choose>

    Maheep

    • Proposed as answer by Maheep Saraf Monday, April 5, 2010 5:27 AM
    Monday, April 5, 2010 5:27 AM
  • 1.  Am I correct in understanding this to be (normally) a non-issue ???

    In other words, has the program already loaded the necessary items from MSBUILD and is thus saying "I really don't need to do this again" ???

    2.  So, apparently with VS 12, the first time I BUILD and RELEASE a solution, I will get the normal BUILD and RELEASE messages (that I got in VS 8 and VS 10), but the second time I BUILD and RELEASE a solution, I will get the normal BUILD messages but will always from this point get the WARNING message for this particular solution ???

    THANKS FOR YOUR HELP !!!

    Jeff


    Jeff McVey

    Monday, November 12, 2012 8:30 PM