Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing Microsoft.Build.Tasks.v4.0.dll on visual studio online tfs build

I am trying to build my project with visual studio online.

I am getting the following error.

C:\a\src\.nuget\nuget.targets (71): The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Build.Tasks.v4.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Build.Tasks.v4.0.dll' or one of its dependencies. The system cannot find the file specified.

This is coming from the nuget.targets file in my solution.

  <UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
        <ParameterGroup>
            <EnvKey ParameterType="System.String" Required="true" />
            <EnvValue ParameterType="System.String" Required="true" />
        </ParameterGroup>
        <Task>
            <Using Namespace="System" />
            <Code Type="Fragment" Language="cs">
                <![CDATA[
                try {
                    Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
                }
                catch  {
                }
            ]]>
            </Code>
        </Task>
    </UsingTask>

I have updated nuget.exe to latest and have not changed anything in nuget.targets.

like image 741
Poul K. Sørensen Avatar asked Dec 14 '13 19:12

Poul K. Sørensen


2 Answers

The problem was that some of the class libraries in the solution had the default value :

ToolsVersion="12.0"

changing that to

ToolsVersion="4.0"

made it work on TFS online

like image 111
Poul K. Sørensen Avatar answered Nov 16 '22 15:11

Poul K. Sørensen


I ran into this after upgrading a project to .NET 4.5.2. Seems to be a conflict between the .NET 4.5 point releases and the old way to do NuGet package restore (MSBuild-Integrated package restore vs Automatic Package Restore).

I was able to solve the issue by migrating NuGet to the new way of doing package restore: http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

More info: http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

like image 30
Chris Hynes Avatar answered Nov 16 '22 16:11

Chris Hynes