Log4Net 配置错误导致 MSBuild 失败

发布于 2025-01-01 00:43:42 字数 2258 浏览 0 评论 0原文

我正在尝试使用 Team City 和 MSbuild 以及 MS 构建社区扩展在新的客户端站点上设置 CI 环境。编译代码似乎工作正常。但是,当我运行单元测试时,我收到来自 NUnit 任务的以下错误:

log4net : error XmlConfigurator: Failed to find configuration section 'log4net' in the   application's .config file.

我已经确定了导致此问题的两个测试项目。但是,我直接从 nunit-console 和 resharper nunit 测试运行程序运行测试,尽管我看到警告,但测试不会失败。我不想在任何项目中对 Log4net 配置文件或 assembly.cs 执行任何操作。我想做的就是使 MSBuild 脚本的行为类似于 Visual Studio,它不会将 log4net 错误视为失败。

这是构建文件

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"      DefaultTargets="Compile">
    <Import Project=".\MSBuild.Community.Tasks.Targets"/>

    <PropertyGroup>
        <Configuration Condition="'$(Configuration)' == ''"> Debug</Configuration>    
    </PropertyGroup>

  <ItemGroup>
    <BuildArtifacts Include=".\build_artifacts\"/>
    <SolutionFile Include ="..\Core.Services.sln"/>
    <NUnitPath Include="..\Packages\NUnit.2.5.10.11092\tools"/>          
  </ItemGroup>

  <Target Name="Clean">
    <RemoveDir Directories="@(BuildArtifacts)"/>
  </Target>

    <Target Name="Init" DependsOnTargets="Clean">
    <MakeDir Directories="@(BuildArtifacts)"/>
  </Target>

    <Target Name="Compile"  DependsOnTargets="Init">    
    <MSBuild            
    Projects="@(SolutionFile)"            
    Targets="Rebuild"
    Properties="OutDir=%(BuildArtifacts.FullPath)">      
    </MSBuild>    
    </Target>

    <Target Name="DevelopmentBuild" DependsOnTargets="Compile">
         <Message Text="Running Unit Tests from %(BuildArtifacts.FullPath)...."      ContinueOnError="true"></Message>

    <CreateItem Include="%(BuildArtifacts.FullPath)*.Tests.dll">
    <Output TaskParameter="Include" ItemName="TestAssembly" />
    </CreateItem>
    <NUnit Assemblies="@(TestAssembly)"
        ToolPath="@(NUnitPath)\"
        ContinueOnError="false"           
        OutputXmlFile="%(BuildArtifacts.FullPath)test-results.xml"
        DisableShadowCopy="true"/>    
      </Target>  
    </Project>

I'm trying to set up a CI environment at a new client site using Team City and MSbuild and the MS build community extensions. Compiling the code seems to work fine. However, when I run my unit tests I get the following error coming from the NUnit task:

log4net : error XmlConfigurator: Failed to find configuration section 'log4net' in the   application's .config file.

I've identified the two test projects that are causing this issue. However, I've ran the tests directly from nunit-console, and the resharper nunit test runner and though I see the warning the tests don't fail. I don't want to do anything with the Log4net configuration file or the assembly.cs in any project. All I want to do is make the MSBuild script behave like Visual Studio which doesn't consider the log4net error as a failure.

Here's the build file

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"      DefaultTargets="Compile">
    <Import Project=".\MSBuild.Community.Tasks.Targets"/>

    <PropertyGroup>
        <Configuration Condition="'$(Configuration)' == ''"> Debug</Configuration>    
    </PropertyGroup>

  <ItemGroup>
    <BuildArtifacts Include=".\build_artifacts\"/>
    <SolutionFile Include ="..\Core.Services.sln"/>
    <NUnitPath Include="..\Packages\NUnit.2.5.10.11092\tools"/>          
  </ItemGroup>

  <Target Name="Clean">
    <RemoveDir Directories="@(BuildArtifacts)"/>
  </Target>

    <Target Name="Init" DependsOnTargets="Clean">
    <MakeDir Directories="@(BuildArtifacts)"/>
  </Target>

    <Target Name="Compile"  DependsOnTargets="Init">    
    <MSBuild            
    Projects="@(SolutionFile)"            
    Targets="Rebuild"
    Properties="OutDir=%(BuildArtifacts.FullPath)">      
    </MSBuild>    
    </Target>

    <Target Name="DevelopmentBuild" DependsOnTargets="Compile">
         <Message Text="Running Unit Tests from %(BuildArtifacts.FullPath)...."      ContinueOnError="true"></Message>

    <CreateItem Include="%(BuildArtifacts.FullPath)*.Tests.dll">
    <Output TaskParameter="Include" ItemName="TestAssembly" />
    </CreateItem>
    <NUnit Assemblies="@(TestAssembly)"
        ToolPath="@(NUnitPath)\"
        ContinueOnError="false"           
        OutputXmlFile="%(BuildArtifacts.FullPath)test-results.xml"
        DisableShadowCopy="true"/>    
      </Target>  
    </Project>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文