visual-studio-2012 - MSBuild 在任务中引用 DLL

标签 visual-studio-2012 msbuild msbuild-task msbuild-4.0

我在应该运行 BeforeBuild 的 .csproj 文件中定义了以下内联任务。

<UsingTask TaskName="VersioningTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
    <FileName ParameterType="System.String" Required="true" />
    <XmlFileName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
    <Reference Include="System.Xml.dll" />
    <Reference Include="System.Xml.Linq.dll"/>
    <Using Namespace="System" />
    <Using Namespace="System.IO" />
    <Using Namespace="System.Linq" />
    <Using Namespace="System.Text" />
    <Using Namespace="System.Text.RegularExpressions" />
    <Using Namespace="System.Xml.Linq" />
    <Code Type="Fragment" Language="cs"><![CDATA[
        var xDoc = XDocument.Load(XmlFileName);
        //...
从 VS2012 构建项目时,出现以下错误:

Could not find reference "System.Xml.dll". If this reference is required by your code, you may get compilation errors.

Could not find reference "System.Xml.Linq.dll". If this reference is required by your code, you may get compilation errors.


如果我删除 XML 内容和两个引用,则构建成功。
我曾尝试使用 DLL (%windir%/assembly) 的完整路径,但没有成功。
非常感谢这里有什么问题的任何想法。

最佳答案

我在引用 System.Xml.Linq 时遇到了同样的问题。切换到编译任务确实可以解决您的解决方案,但要将原始代码实现为内联任务,只需从引用中删除文件扩展名,然后删除内联任务,以便引用根命名空间而不是文件名。

改变这个:

<Reference Include="System.Xml.dll" />
<Reference Include="System.Xml.Linq.dll"/>

阅读:
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"/>

关于visual-studio-2012 - MSBuild 在任务中引用 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16182179/

相关文章:

c++ - 获取错误 "Debug Assertion Failed"

asp.net-mvc - 在 VS 2012 中创建 MVC4 项目时出现 NuGet 错误

c# - 如何在我的新 CSPROJ 类库中包含带有 native dll 的 NuGet 包?

git - 让 NuGet 与整个解决方案和其中包含的单个项目一起工作

msbuild - 你如何在 MSBuild 中格式化文本?

asp.net - 使用 ASP.NET 将二进制写入新选项卡/窗口

c++ - VS2012 中的 strtof() 在哪里?

xslt - 您使用什么 XSLT 来格式化 CruiseControl.Net 中的 MsBuild XML 输出?

c# - 签署 EXE 时出现 "File has a different computed hash than specified in manifest"错误