dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

Running custom build actions from the command line #3489

Closed define-private-public closed 1 year ago

define-private-public commented 6 years ago

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>
Therzok commented 6 years ago

@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:

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