简体   繁体   English

C#nant使用.csproj文件构建

[英]C# nant build using .csproj files

Typically when doing a build script for C# I just include **/*.cs for each project/dll to build. 通常在为C#执行构建脚本时,我只需为每个要构建的项目/ dll包含** / * .cs。 However I now have a situation where I have some .cs files which are not part of the project but live in that directory (they are there for reference purposes from another library). 但是我现在有一种情况,我有一些.cs文件,这些文件不是项目的一部分,而是存在于该目录中(它们可以从另一个库中进行参考)。 There are not linked in the .csproj file so the VS build works fine but the nant build does not. .csproj文件中没有链接,因此VS构建工作正常,但是nant构建没有。

Does anyone know if there's a nice easy way of pulling the .cs entries out of the relevant .csproj file and using that as the list of source files to build rather than using a general wildcard match. 有没有人知道是否有一种很简单的方法可以将.cs条目从相关的.csproj文件中拉出来,并将其用作构建的源文件列表,而不是使用通用的通配符匹配。

Thanks in advance. 提前致谢。

Any particular reason you don't want to use msbuild just for the C# build bit ? 你不想仅仅为C#构建位使用msbuild的任何特殊原因? That's what I do for my Protocol Buffers port, and it works well. 这就是我为Protocol Buffers端口所做的工作,而且效果很好。 It does require nant-contrib , but that's not much of a hardship. 确实需要nant-contrib ,但这并不是很困难。

That way you know you only need to get one thing working, and know it'll be built the same way. 这样你知道你只需要让一件事工作,并且知道它将以同样的方式构建。

You can have a look at my ProtoBuf port build file here , for inspiration. 您可以在这里查看我的ProtoBuf端口构建文件,以获取灵感。 The obvious downside is Mono support, but I believe xBuild is improving... 明显的缺点是Mono支持,但我相信xBuild正在改进......

nant has support for automatically building VS solutions, including csproj files, using a <solution> task. nant 支持使用<solution>任务自动构建VS解决方案,包括csproj文件。

The latest supported solution format is VS 2003. 最新支持的解决方案格式是VS 2003。

Nantcontrib includes an msbuild task - you can use this to build both projects and solutions. Nantcontrib包含一个msbuild任务 - 您可以使用它来构建项目和解决方案。 Here's an example of it in practice: http://web.archive.org/web/20100913051600/http://codebetter.com/blogs/jeffrey.palermo/archive/2006/08/12/148248.aspx 以下是实践中的一个示例: http//web.archive.org/web/20100913051600/http : //codebetter.com/blogs/jeffrey.palermo/archive/2006/08/12/148248.aspx

您可以通过Exec任务使用MSBuild构建项目,而不是直接调用编译器,例如msbuild project.csproj

Using MSBuild is a great idea. 使用MSBuild是一个好主意。 However, if there are any orphaned files (.cs files not in .csproj), aspnet_compile.exe will sometimes fail. 但是,如果有任何孤立文件(.cs文件不在.csproj中),aspnet_compile.exe有时会失败。 To get around this I wrote the following to remove all *.cs files that are not included in the .csproj. 为了解决这个问题,我编写了以下内容来删除.csproj中未包含的所有* .cs文件。 So far so good, any feedback is appreciated. 到目前为止一切顺利,任何反馈都表示赞赏。

<project>
 <foreach item="File" property="csprojFile">
 <in>
  <items>
   <include name="source/**/*.csproj" />
  </items>
 </in>
 <do>
  <property name="currentFolder" value="${directory::get-current-directory()}" />
  <property name="csprojParentFolder" value="${directory::get-parent-directory(csprojFile)}" />

  <foreach item="File" property="csFile">
   <in>
    <items>
     <include name="${csprojParentFolder}/**/*.cs"/>
    </items>
   </in>
   <do>

    <property name="csFileRelativePath" value="${string::replace(csFile, csprojParentFolder + '\', '')}" />
    <loadfile property="projFile" file="${csprojFile}" />
    <if test="${not string::contains(projFile, csFileRelativePath)}">
     <echo message="${csprojFile}:  | Missing: ${csFileRelativePath}" />
     <!-- <delete file="${csprojParentFolder + '\' + csFileRelativePath}" /> -->
    </if>
   </do>
  </foreach>

 </do>
 </foreach>
</project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM