在MonoDevelop和Visual Studio上使用post-build脚本制作项目的最佳方法是什么?

时间:2022-10-17 12:09:02

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).

我有一个开源项目,我试图在MonoDevelop(包括* nix)和Visual Studio上进行开发。我最近发现的一个要求是我需要将输出文件从一个目录复制到另一个目录(相对路径)。

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?

但是,Windows具有copy命令,而* nix具有cp命令。在两个平台上使用它并解决这些命令差异的最佳方法是什么?

3 个解决方案

#1


8  

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:

您可以使用$ OS变量根据环境具有不同的后期构建事件。为此,您必须手动编辑csproj,如:

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

#2


5  

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.

在可能的情况下,如果您可以依靠内置的MSBuild任务而不是自定义shell脚本,那么该行为通常可以在xbuild(因而是MonoDevelop?)上运行而无需任何更改,因此不需要特定于平台的* 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

这来自单声道文档:http://www.mono-project.com/archived/porting_msbuild_projects_to_xbuild/#prepostbuildevents

#3


0  

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.

您可以用Python之类的语言编写post构建脚本。或者您可以要求其他开发人员安装GnuWin32 CoreUtils作为安装CygWin的选项。 CoreUtils包括cp。然后你可以无条件地使用cp。

#1


8  

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:

您可以使用$ OS变量根据环境具有不同的后期构建事件。为此,您必须手动编辑csproj,如:

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

#2


5  

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.

在可能的情况下,如果您可以依靠内置的MSBuild任务而不是自定义shell脚本,那么该行为通常可以在xbuild(因而是MonoDevelop?)上运行而无需任何更改,因此不需要特定于平台的* 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

这来自单声道文档:http://www.mono-project.com/archived/porting_msbuild_projects_to_xbuild/#prepostbuildevents

#3


0  

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.

您可以用Python之类的语言编写post构建脚本。或者您可以要求其他开发人员安装GnuWin32 CoreUtils作为安装CygWin的选项。 CoreUtils包括cp。然后你可以无条件地使用cp。