MSB4067:元素&lt; #text&gt;元素<target>下方无法识别

时间:2018-05-19 04:30:09

标签: visual-studio msbuild

从visual studio,我能够成功编译代码但是当我尝试使用MSBuild编译代码时,它会抛出我的错误,如下所示

  

MSB4067:元素&lt; #text&gt;在元素下面Target无法识别。

请注意:我在发布模式下使用MSBuild构建代码,我为AfterTarget添加的代码仅用于调试模式。

如果我删除代码,即它工作正常。

这是我的csproj文件

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B9B35177-B239-41A9-946F-3BB1CC14BD3B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ABC.MyProject.Engine</RootNamespace>
<AssemblyName>ABC.MyProject.Engine</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
 </PropertyGroup>
 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="ABCDataAccess, Version=2017.2.1.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\internal\ABCDataAccess.dll</HintPath>
</Reference>
<Reference Include="ABCNotifier, Version=2016.2.2.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\internal\ABCNotifier.dll</HintPath>
</Reference>
<Reference Include="ABCScheduler, Version=2016.2.2.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\internal\ABCScheduler.dll</HintPath>
</Reference>
<Reference Include="log4net">
  <HintPath>..\lib\thirdparty\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<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>
<ItemGroup>
<Compile Include="core.cs" />
<Compile Include="Model\FileInstance.cs" />
<Compile Include="Model\FileLifeCycle.cs" />
<Compile Include="Model\StateExecutor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
  <AutoGen>True</AutoGen>
  <DesignTimeSharedInput>True</DesignTimeSharedInput>
  <DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Enterprise\Implementation\FileKarmaHandler.cs" />
<Compile Include="Enterprise\Implementation\FileKarma.cs" />
<Compile Include="Enterprise\Implementation\FileLifeCycleData.cs" />
<Compile Include="Enterprise\Interface\IFileLifeCycleData.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
  <Generator>SettingsSingleFileGenerator</Generator>
  <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\ABC.MyProject.Core.csproj">
  <Project>{E1B4DF28-23C5-4865-B7B7-51707D2116E3}</Project>
  <Name>ABCCore</Name>
 </ProjectReference>
 </ItemGroup>
<ItemGroup>
<Content Include="Config\Archiver.xml" />
<Content Include="Config\ABClog.xml" />
<Content Include="Config\DataAccess.xml" />
<Content Include="Config\Notifier.xml" />
<Content Include="Config\Security.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
  rmdir config
  mkdir config
  rmdir sqls
  mkdir sqls
  rmdir templates
  mkdir templates
  exit 0
</PreBuildEvent>
</PropertyGroup>

<PropertyGroup>
 <PostBuildEvent>
  copy $(ProjectDir)Config\*.xml config\
  copy $(ProjectDir)..\lib\thirdparty\*.* $(ProjectDir)\bin\$(Configuration)\
  copy $(ProjectDir)..\Core\Config\*.xml config\
  copy $(ProjectDir)..\Core\sqls\*.*  sqls\
</PostBuildEvent>
</PropertyGroup>

<UsingTask TaskName="XmlPreprocess" AssemblyFile="..\lib\msbuild\lib\XmlPreprocess.MSBuildTasks.dll" />

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Debug' ">
 
<PropertyGroup> 
 <ConfigValuesSpreadsheetFileLocation>
  ..\lib\msbuild\config\Settings.xls
</ConfigValuesSpreadsheetFileLocation>
</PropertyGroup>
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="..\Core\Config\AlertParams.xml"
  OutputFiles="bin\Debug\config\AlertParams.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="..\Core\Config\CoreParams.xml"
  OutputFiles="bin\Debug\config\CoreParams.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="..\Core\Config\StateParams.xml"
  OutputFiles="bin\Debug\config\StateParams.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="Config\Archiver.xml"
  OutputFiles="bin\Debug\config\Archiver.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="Config\DataAccess.xml"
  OutputFiles="bin\Debug\config\DataAccess.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="app.config"
  OutputFiles="bin\Debug\app.config"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />

  </Target>

</Project>

3 个答案:

答案 0 :(得分:1)

我已经看到当XML格式错误(例如,具有重复的>字符)时会发生此错误。 要对其进行故障排除,您可以从csproj中删除XML节点,直到错误消失(错误应该在构建开始时就出现),然后重复进行直到您缩小到XML问题的特定行为止。

答案 1 :(得分:0)

  

MSB4067:元素&lt; #text&gt;元素下面是无法识别的

首先,您应该使用Visual Studio中的MSBuild而不是.Net Framework。

因为从Visual Studio 2013开始,2013版本的MSBuild将作为Visual Studio的一部分而不是.NET Framework发布。有关详细信息,请查看this blog。所以你应该使用MSBuild:

C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe

其次,在发布模式下通过MSBuild构建项目时,应该提供配置参数/P:configuration=Release,命令如下:

msbuild "YourProjectPath.csproj" /P:configuration=Release

希望这有帮助。

答案 2 :(得分:0)

注意源代码管理中的合并/冲突标记。我刚刚遇到了导致此错误的 GIT 标记。

相关问题