在Visual Studio Online TFS构建中缺少Microsoft.Build.Tasks.v4.0.dll

9

我正在尝试使用Visual Studio Online构建我的项目。

我遇到了以下错误。

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.

这是来自我的解决方案中的nuget.targets文件。
  <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>

我已经将nuget.exe更新到最新版本,但是在nuget.targets文件中没有做任何修改。


可能是在TFS 2013上构建失败但本地正常的重复问题。 - Korayem
2个回答

12

问题是解决方案中部分类库具有默认值:

ToolsVersion="12.0"

更改为

ToolsVersion="4.0"

使其在TFS在线上运作


3
csproj 文件用于项目。 - Poul K. Sørensen

4

这个解决方案是正确的选择,因为@pksorensen更像是一个不太专业的黑客,不能很好地解决问题。 - Korayem
@Korayem,同意,自动程序包恢复的迁移对我来说也解决了这个问题。 - Vadim K.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接