开发者

is it a common thing to edit the csproj file in build scripts?

I want my build script to automatically add (or delete) files from my c# project on build. I see entries in the csproj file that tell vs2010 that the file is in the project are rela开发者_运维技巧tively simple.

I'm thinking I can just edit the csproj file using a build script to add files that should be in there and delete files that shouldn't be based on some logic the build script runs.

Will someone try to talk me out of this?

Thanks

Isaac


It's not a common thing, no.

I dislike it for a very simple reason: if you run the build script on your local checkout, it will change the checkout. The perfect build script, in my book, is reversible by simply deleting the build output and any intermediate directories.

If you want to include / exclude a file based on where it's built, then the best thing to do would be to create an extra build configuration, set a special conditional compilation symbol in it, and use #if in the source file.

Alternatively you could simply put a Condition attribute on the file in .csproj, since it's just an MSBuild file. Something like this:

<ItemGroup>
  <Compile Include="Something.cs" Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "/>

(note - I haven't tested the above but I think it should work)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜