TeamCity: Failed to detect target in MSBuild project

。_饼干妹妹 提交于 2019-12-08 21:18:48

问题


I have some problems with the TeamCity MSBuild replacement I think.

I've tried to compile a Delphi 2010 Project (MSBuild compliant) with NAnt using the MSBuild task (NAnt Contrib).

Everything works fine, if I do it without TeamCity on the console.

If I try it with TeamCity, I get the following error message:

Failed to detect default target(s) in the project file  F:\CI\TeamCity\TeamCity\buildAgent\work\892195dab42324a3\build\src.temp\TestProject\Test.dproj.  Please define targets explicitly in the build configuration options on  TeamCity Web UI. Project does not define DefaultTargets or  InitialTargets.

I've tried to explicitly set the target via the MSBuild /target switch pointing to the Rebuild target. So far no luck.

Any Suggestions? Thanks in advance.

Edit:

    <foreach item="File" property="iterator.dproj">
        <in>
            <items>
                <include name="${src.temp}\**\*.dproj" />
            </items>
        </in>
        <do>
            <msbuild project="${iterator.dproj}">
                <arg value="/target:Rebuild" />                 
            </msbuild>
        </do>
    </foreach>

The *.dproj file is a standard delphi 2010 project file (it's transformed with xsl but it's still a valid project file)

Edit2:

Thanks to s. ermakovich, I replaced the msbuild task (from NAnt contrib) with the direct call to NAnt, which does not produce the error on TeamCity server. Looks like TeamCity does only replace the call to NAnt contrib msbuild task. :-)

    <property name="msbuild.exe" value="${framework::get-framework-directory(nant.settings.currentframework)}\msbuild.exe" />
    <foreach item="File" property="iterator.dproj">
        <in>
            <items>
                <include name="${src.temp}\**\*.dproj" />
            </items>
        </in>
        <do>
            <exec program="${msbuild.exe}">
                <arg path="${iterator.dproj}" />
            </exec>
        </do>
    </foreach>

回答1:


It seems that you are using /target switch in your console command line. Please, try to specify target(s) that you need in the build configuration options on TeamCity Web UI, as it is suggested by the error message. Yon can find this parameter on the Runner tab of the TeamCity project configuration. Enter targets separated by space or semicolon. Build, Rebuild, Clean, Publish targets are supported by default.




回答2:


I encountered this issue while creating the project in VS2017. It added the project as TooVersion="15.0" and there is no DefaultTargets attribute. I changed it 2015 since my team city msbuild option is 2015. So both now sync

<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">



回答3:


Rather than specifying the build target on the command line or in teamcity, you can ensure that DefaultTargets="..." is defined on the <Project> tag in the project file.



来源:https://stackoverflow.com/questions/4041168/teamcity-failed-to-detect-target-in-msbuild-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!