TeamCity忽略AfterTargets

时间:2011-08-24 15:22:04

标签: msbuild teamcity

我的设置类似于以下内容:

Test.csproj :(默认Windows控制台应用程序,无更改)

Test.csproj.user:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="Test.csproj.targets" />
</Project>

Test.csproj.targets:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="AfterCoreCompile" AfterTargets="CoreCompile">
    <Message Text="In AfterCoreCompile" />
  </Target>
</Project>

使用Visual Studio,输出如下所示:

------ Build started: Project: Test, Configuration: Debug x86 ------
Build started 8/24/2011 10:48:04 AM.
CoreCompile:
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\x86\Debug\Test.exe /target:exe Program.cs Properties\AssemblyInfo.cs
AfterCoreCompile:
  In AfterCoreCompile
CopyFilesToOutputDirectory:
  Copying file from "obj\x86\Debug\Test.exe" to "bin\Debug\Test.exe".
  Test -> C:\Users\...\Desktop\Test\Test\bin\Debug\Test.exe
  Copying file from "obj\x86\Debug\Test.pdb" to "bin\Debug\Test.pdb".

Build succeeded.

Time Elapsed 00:00:00.09
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

在TeamCity中,它看起来像这样:

[10:50:05]: Skip checking for changes - there are no VCS roots defined
[10:50:05]: Clearing temporary directory: C:\TeamCity\buildAgent\temp\buildTmp
[10:50:05]: Checkout directory: C:\TeamCity\buildAgent\work\532794d203990edb
[10:50:05]: Repository sources transferred
[10:50:05]: Updating sources: server side checkout...
[10:50:05]: Publishing internal artifacts (4s)
[10:50:09]: [Publishing internal artifacts] Sending build.start.properties file
[10:50:05]: Starting: C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:C:\Users\buildbot\Desktop\Test /msbuildPath:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
[10:50:05]: in directory: C:\Users\buildbot\Desktop\Test
[10:50:06]: Targets was not defined in the build configuration.
[10:50:09]: Test.csproj.teamcity: Build target: Build
[10:50:09]: [Test.csproj.teamcity] CoreCompile
[10:50:09]: [CoreCompile] Csc
[10:50:09]: [Csc] C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\x86\Debug\Test.exe /target:exe Program.cs Properties\AssemblyInfo.cs
[10:50:09]: [Csc] CSC warning CS1607: Assembly generation -- Referenced assembly 'mscorlib.dll' targets a different processor
[10:50:09]: [Csc] CSC warning CS1607: Assembly generation -- Referenced assembly 'System.Data.dll' targets a different processor
[10:50:09]: [Test.csproj.teamcity] CopyFilesToOutputDirectory
[10:50:09]: [CopyFilesToOutputDirectory] Copy
[10:50:09]: [Copy] Copying file from "obj\x86\Debug\Test.exe" to "bin\Debug\Test.exe".
[10:50:09]: [CopyFilesToOutputDirectory] Test.csproj -> C:\Users\Buildbot\Desktop\Test\bin\Debug\Test.exe
[10:50:09]: [CopyFilesToOutputDirectory] Copy
[10:50:09]: [Copy] Copying file from "obj\x86\Debug\Test.pdb" to "bin\Debug\Test.pdb".
[10:50:10]: Process exited with code 0
[10:50:10]: Publishing internal artifacts
[10:50:10]: [Publishing internal artifacts] Sending build.finish.properties file
[10:50:10]: Build finished

那么为什么TeamCity会忽略我的AfterTargets目标?

1 个答案:

答案 0 :(得分:1)

发生这种情况的原因是因为TeamCity忽略了* .csproj.user文件,尽管它们可能存在于VCS中。将<Import Project="..." />行移动到* .csproj文件中会产生正确的行为。