Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a custom target to .csproj file

I want to add a custom target in my .csproj file.

The custom target will be :

msbuild /t:assembleDebug

This target will just build with the Debug mode.

I have already try to modify the .csproj file but no success.

Thanks for your answers.

like image 642
leyh Avatar asked Dec 10 '22 08:12

leyh


1 Answers

This target will just build with the Debug mode. I have already try to modify the .csproj file but no success.

To accomplish this, unload your project. Then at the very end of the project, just before the end-tag </Project>, place below scripts:

  <Target Name="assembleDebug" Condition=" '$(Configuration)' == 'Debug' ">

    <Message Text="This custom target will only be executed when configuration is debug" Importance="high"></Message>
  </Target>

With the condition '$(Configuration)' == 'Debug', the target will only be executed when configuration is Debug:

enter image description here

When you build it with the Release mode, this custom target will not be executed:

msbuild "CustomTarget.csproj" /p:Configuration=Release /t:build;assembleDebug

Update for comment:

Can I just call : msbuild /t:assembleDebug and this target will do the same thing as msbuild /p:Configuration=Debug

/p:Configuration=Release is used to overwrite the default configuration on Visual Studio, if you just want call : msbuild /t:assembleDebug and this target will do the same thing as msbuild /p:Configuration=Debug, you should set the default configuration to Debug, then build it with the command msbuild /t:assembleDebug:

enter image description here

Then build it with that command line:

enter image description here

Hope this helps.

like image 94
Leo Liu-MSFT Avatar answered Jan 05 '23 00:01

Leo Liu-MSFT