【问题标题】:Missing Microsoft.Build.Tasks.v4.0.dll on visual studio online tfs buildVisual Studio Online tfs build 上缺少 Microsoft.Build.Tasks.v4.0.dll
【发布时间】:2013-12-14 19:41:11
【问题描述】:

我正在尝试使用 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 azure-devops


【解决方案1】:

问题是解决方案中的某些类库具有默认值:

ToolsVersion="12.0"

改成

ToolsVersion="4.0"

让它在在线 TFS 上运行

【讨论】:

  • 项目的csproj文件
【解决方案2】:

我在将项目升级到 .NET 4.5.2 后遇到了这个问题。似乎是 .NET 4.5 点版本和执行 NuGet 包还原的旧方法(MSBuild-Integrated 包还原与自动包还原)之间的冲突。

我能够通过将 NuGet 迁移到执行包还原的新方法来解决该问题:http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

更多信息:http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

【讨论】:

  • 这个解决方案是正确的方法,因为@pksorensen 更像是一个不能正确解决问题的黑客。
  • @Korayem,同意,迁移到自动包还原也解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 2012-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-02
  • 1970-01-01
相关资源
最近更新 更多