MSBuild - 包括引用

时间:2013-12-14 22:19:56

标签: msbuild visual-studio-2013

我正在努力学习MSBuild;首先,我有一个C#项目文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <RootNamespace>$(MSBuildProjectName)</RootNamespace>
    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
    <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>

  <Target Name="Build">
    <Csc 
      AdditionalLibPaths="C:\Windows\Microsoft.NET\Framework\v4.0.30319\" 
      References="@(Reference)"
      Sources="@(Compile)" 
      OutputAssembly="$(MSBuildProjectName).exe" 
      />
  </Target>
</Project>

然而,CSC失败了,说它无法找到元数据文件'xyz',对于我试图包含的每个引用都是如此。此外,Visual Studio报告了类似的问题:

MSBuild References Problem

那么我做错了什么?

1 个答案:

答案 0 :(得分:0)

由于目标名称=“构建”

而导致此错误的原因
   <Target Name="Build">
      <Csc AdditionalLibPaths="C:\Windows\Microsoft.NET\Framework\v4.0.30319\"
      References="@(Reference)" 
      Sources="@(Compile)" OutputAssembly="$(MSBuildProjectName).exe" />
   </Target>

特别是这一行:

     <Csc AdditionalLibPaths="C:\Windows\Microsoft.NET\Framework\v4.0.30319\" 
      References="@(Reference)" 
      Sources="@(Compile)" OutputAssembly="$(MSBuildProjectName).exe" />

如果您不需要,可以删除此额外的lib路径,如果需要在Web上搜索,您应该可以很好地设置AddtionalLib路径。 This可能会对您有所帮助。