This project has moved. For the latest updates, please go here.

How to use NsDepCop without installing it?

Dec 2, 2013 at 2:34 AM

I'm trying to deploy NsDepCop as a shared MSBuild task for the whole project without installing it in everyone's machine. I tried the following step:
  1. Note: I don't have any custom tasks before NsDepCop.
  2. Comment the elements inside <Project /> in "C:\Program Files (x86)\MSBuild\v4.0\Custom.After.Microsoft.CSharp.targets" and made sure NsDepCop won't start.
  3. Copy everything from "C:\Program Files (x86)\MSBuild\v4.0\" to one of the sub-folders.
    3 Import it in AfterBuild:
<Target Name="AfterBuild">
  <Message Text="$(MyNsDepCopTaskFolder)\Cusoms.After.Microsoft.CSharp.targets" />
  <Import Project="$(MyNsDepCopTaskFolder)\Cusoms.After.Microsoft.CSharp.targets" />
I printed the path of the targets and made sure it's correct, but VS always says:
The "Import" task was not found. Check the following:
  1. The name of the task in the project file is the same as the name of task class.
  2. The task class is "public" and implements the Microsoft.Build.Framework.ITask interface.
  3. The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framekwork\v4.0.30319" directory.
Anything I did wrong?

Mar 29, 2014 at 2:44 PM
Hi Jeff,
Sorry, for not answering until now. Somehow I missed your question. I don't know whether it was me or codeplex...
Anyway, do you still have this problem or have you managed to work it out?

Mar 29, 2014 at 3:20 PM
I think I know what your problem was. The MsBuild "Import" element cannot be the child of a "Target" element. It must be the child of the "Project" element.
But you don't really need to import that targets file. You can directly import the NsDepCopTask with the "UsingTask" element like this.
<Project ... >

  ... the content of your project file ...

  <UsingTask AssemblyFile="the-relative-path-to-nsdepcop-files\NsDepCop.MsBuildTask.dll" TaskName="Codartis.NsDepCop.MsBuildTask.NsDepCopTask" />
  <Target Name="AfterBuild">
    <NsDepCopTask ReferencePath="@(ReferencePath)" Compile="@(Compile)" BaseDirectory="$(MSBuildProjectDirectory)" />