Msbuild: Running custom build actions from the command line

Created on 8 Jul 2018  路  1Comment  路  Source: dotnet/msbuild

Right now I'm developing a applications that has plugins using MonoDevelop. After successfull bulid (or clean), I added some custom actions to be executed (e.g. copy the plugins to a specific directory, or clean them from it).

When I run Build/Rebuild/Clean through MonoDevelop, these actions are executing. But lets say that I'm using msbuild from the command line, then they aren't run. Is there an argument I need to pass in?

Here is an example of what is in my .csproj file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <CustomCommands>
      <CustomCommands>
        <Command>
          <type>AfterBuild</type>
          <command>copy_plugins.sh</command>
        </Command>
        <Command>
          <type>BeforeClean</type>
          <command>clean_plugins.sh</command>
        </Command>
      </CustomCommands>
    </CustomCommands>
  </PropertyGroup>

Most helpful comment

@define-private-public CustomCommands are a legacy MonoDevelop way of handling arbitrary target running, back when we didn't properly support msbuild.

Right now, you can write targets using dependencies and msbuild built-in functions: https://msdn.microsoft.com/en-us/library/ms171462.aspx

To have the functionality work in both MSBuild and MonoDevelop, you could do the following:

  • Remove the CustomCommand definitions
  • Add these 2 targets:
<Target Name="AfterBuild" >  
    <Exec Command="sh copy_plugins.sh" Condition=" '$(Configuration)' == 'Debug'" />
</Target>
<Target Name="BeforeClean" >  
    <Exec Command="sh clean_plugins.sh" Condition=" '$(Configuration)' == 'Debug'" />
</Target>

Since I don't know what those shell files do, I could not port them to using msbuild functionality.

>All comments

@define-private-public CustomCommands are a legacy MonoDevelop way of handling arbitrary target running, back when we didn't properly support msbuild.

Right now, you can write targets using dependencies and msbuild built-in functions: https://msdn.microsoft.com/en-us/library/ms171462.aspx

To have the functionality work in both MSBuild and MonoDevelop, you could do the following:

  • Remove the CustomCommand definitions
  • Add these 2 targets:
<Target Name="AfterBuild" >  
    <Exec Command="sh copy_plugins.sh" Condition=" '$(Configuration)' == 'Debug'" />
</Target>
<Target Name="BeforeClean" >  
    <Exec Command="sh clean_plugins.sh" Condition=" '$(Configuration)' == 'Debug'" />
</Target>

Since I don't know what those shell files do, I could not port them to using msbuild functionality.

Was this page helpful?
0 / 5 - 0 ratings