Custom task: assembly could not be found

Hi,

I am using the final version of Framework 2.0. I have created a custom task called SimpleTask (modelled after the Hands-On-Lab document). When I try to use it in a project file, I get the following error message:

C:\tmp\I2DL\i2dl.proj(11,5): error MSB4062: The "SimpleTask" task could not be l
oaded from the assembly c:\tmp\vs6build\vs6build\bin\Debug\v6build.dll. Could no
t load file or assembly 'file:///c:\tmp\vs6build\vs6build\bin\Debug\v6build.dll'
 or one of its dependencies. The system cannot find the file specified. Confirm
that the <UsingTask> declaration is correct, and that the assembly and all its d
ependencies are available.
    0 Warning(s)
    1 Error(s)

This is my project file:

<Project DefaultTargets="build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <UsingTask
       TaskName="SimpleTask"
       AssemblyFile="c:\tmp\vs6build\vs6build\bin\Debug\v6build.dll"
   />

   <ItemGroup>
      <vsprojects Include="i2dl.dsw"/>
   </ItemGroup>
   <Target Name="Buildv6">
       <SimpleTask Executable="C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\msdev.exe" />
       <SimpleTask Buildargs="\/nologo \/f i2dl.dsw \/make" />
       <SimpleTask Basedirectory="c:\tmp\i2dl" />
  </Target>   
  <Target Name="build" DependsOnTargets="Buildv6">
     
   </Target>
</Project>

The assembly is located as it says in the project file. Is this a problem of the references Microsoft.Build.Framework.dll and Microsoft.Build.Utilities.dll

I am trying to make a custom task for building Visual C++ 6 projects - using the exec task will not include error logging as I have understood it.

/Chris


Answer this question

Custom task: assembly could not be found

  • M_Luka

    Try adding the full path to the project file to the SafeImports reg key in the registry.  The location of the regkey is:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\MSBuild\SafeImports

    I saw this problem just the other day and this fixed it.  A better way to do this is to put your <UsingTask ...> in some <pick_a_name>.targets file and drop this targets file into a location that you can <Import ...> into your project file.  Then put the full path to the targets file into the SafeImports section of the registry.  This way, you only have to add the targets file once.  The other way you would have to add each project file you use it in to SafeImports, well at least the ones you load into VS 2005.

  • Kapadia Shalin

    gacutil -l | grep - build:

      Microsoft.Build.VisualJSharp, Version=2.0.0.0, Culture=neutral, PublicKeyToken
    =b03f5f7f11d50a3a, processorArchitecture=x86
      Microsoft.Build.Engine, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5
    f7f11d50a3a, processorArchitecture=MSIL
      Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b0
    3f5f7f11d50a3a, processorArchitecture=MSIL
      Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f
    7f11d50a3a, processorArchitecture=MSIL
      Microsoft.Build.Utilities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b0
    3f5f7f11d50a3a, processorArchitecture=MSIL
      Microsoft.CompactFramework.Build.Tasks, Version=8.0.0.0, Culture=neutral, Publ
    icKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
      Microsoft.VisualStudio.OfficeTools.Build.Tasks, Version=8.0.0.0, Culture=neutr
    al, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
      PresentationBuildTasks, Version=6.0.4030.0, Culture=neutral, PublicKeyToken=31
    bf3856ad364e35, processorArchitecture=MSIL

    So the dll's are in the GAC.

    /Chris

  • pure

    Hi,
    Not really sure if this is your problem but if the v6build.dll file is where it is supposed to be then also check to make sure that all of its dependencies are also in a location that MSBuild will look. In your case I think the solution is to place the other needed assemblies in the same folder as the v6build.dll. Let me know if this works.

    Sayed Ibrahim Hashimi

  • dougseven

    Thanks, it worked.

    /Chris

  • anelson45

    Hi,

    Thanks for answering me.

    The only dependencies are Microsoft.Build.Framework.dll and Microsoft.Build.Utilities.dll which are found in the Framework path. This path is included in the PATH environment variable.

    Here are my using statements:

    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Threading;
    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;

    /Chris

  • hfleong

    Besides looking at your code and project file, I'm all out of ideas. If you want to post the code/project file here I'll have a look at it, or you can email them to me sayed [DOT] hashimi [AT] gmail [dot] com

  • JeffGoneMad

    Neil, the problem you run into is that you still have to put the full path into the MSBuild->SafeImports section of the registry to shut up VS when it loads the project using the custom task.  I wonder if these registry entries could handle environment variables
  • Dj Jamminx

    Derek,

    Is your proejct under source control, and does your team sync to that source control depot If so your best bet is to check your tasks directly into your source control system. That way when developers enlist and bring down the tree they get all your custom assemblies and whatnot. This is what we do for our internal build system.

    When you've done that you can then make the AssemblyFile path relative, or based on an environment variable. For example you could make it be something like <UsingTask AssemblyFile="$(MSBuildToolRoot)\EnterpriseBuildTasks.dll">, and then set MSBuildToolRoot in your command-line window to point to whatever the path to the enlisted directory with tools is.

    Does that make sense It's a little late, I might be babbling stuff that sounds like crazy talk :)

    Neil

  • Glaciered Pyro

    I'm having a similar problem, except I'm using the AssemblyName attribute of <UsingTask> instead of the AssemblyFile attribute.  I actually don't have a problem if I specify the path to the assembly as in:

    <UsingTask AssemblyFile="C:\Windows\Microsoft.NET\Framework\v2.0.50727\EnterpriseBuildTasks.dll" TaskName="Publish"/>

    I'm using the final release, but the examples I've followed don't seem to work properly.  Is this a bug   Can you explain what the SafeImports registry entry is suppose to do   One of the reasons I've been looking as MSBuild over NAnt is so I can have my team not have to install special software and do special stuff to actually get the build working.  Having to mess with the registry seems like a kludge workaround.

    Derek Greer

  • Ruske

    Having the path point to the Framework directory is not sufficient. Microsoft.Build.Framework.dll and Microsoft.Build.Utilities.dll need to either be in the GAC for Fusion to find them, or they need to be in the same directory as your task assembly. Try copying them over to the location of your task assembly.

    (Also run gacutil -l to check if the MSBuild assemblies are installed.)


  • moronikos

    Did you build that task with the same version of the Framework that you are trying to execute it with

  • QUEST 2005

    Not sure if you've tried this - but you can also use the Fusion Log Viewer to get more details on failed assembly binds.  Run fuslogvw from a Visual Studio Command prompt, and enable logging for failed binds, run your project and examine the log.

    Faisal


  • RosarioDsilva

    This is the output from the log viewer:

    ** Assembly Binder Log Entry (07-11-2005 @ 09:04:41) ***

    The operation failed.
    Bind result: hr = 0x80070002. The system cannot find the file specified.

    Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\mscorwks.dll
    Running under executable c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\Msbuild.exe
    --- A detailed error log follows.

    === Pre-bind state information ===
    LOG: User = 7TDK\chs
    LOG: Where-ref bind. Location = E:\DEV\Other\vs6build\vs6build\bin\Debug\v6build.dll
    LOG: Appbase = file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50215/
    LOG: Initial PrivatePath = NULL
    LOG: Dynamic Base = NULL
    LOG: Cache Base = NULL
    LOG: AppName = Msbuild.exe
    Calling assembly : (Unknown).
    ===
    LOG: This bind is in LoadFrom load context.
    WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
    LOG: No application configuration file found.
    LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\config\machine.config.
    LOG: Attempting download of new URL file:///E:/DEV/Other/vs6build/vs6build/bin/Debug/v6build.dll.
    LOG: All probing URLs attempted and failed.
    /Chris

  • Mustang33

    Yes.

    I have tried with beta 2.0 framework and final version (recompiled the task) but both failed.

    /Chris

  • Custom task: assembly could not be found