简体   繁体   中英

Best way to make a project with post-build script work on MonoDevelop and Visual Studio?

I have an open source project in which I'm trying to allow development on both MonoDevelop(including *nix) and Visual Studio. One of my recently discovered requirements is I need to copy an outputted file from one directory to another(relative path).

Windows however has the copy command, while *nix has the cp command. What is the best way to get this to work on both platforms and resolve this difference of commands?

You can use the $OS variable to have different post build events depending on the environment. To do this, you must edit the csproj by hand, like:

<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' ">
    dir
</PostBuildEvent>
<PostBuildEvent Condition="'$(OS)' != 'Windows_NT'">
    ls
</PostBuildEvent>

Where possible, if you can lean on built-in MSBuild tasks rather than custom shell scripting, the behavior will generally work on xbuild (and hence MonoDevelop?) without any changes, so no need for platform-specific *proj hacks.

eg:

 <Target Name="AfterBuild">
          <Copy SourceFiles="foo.txt" DestinationFolder="$(OutDir)" />
 </Target>

This is from the mono docs: http://www.mono-project.com/archived/porting_msbuild_projects_to_xbuild/#prepostbuildevents

You could write the post build script in a language like Python. Or you could require other developers to install GnuWin32 CoreUtils as an option to installing CygWin. CoreUtils includes cp. Then you can just unconditionally use cp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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