Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post-build event command for publish (Visual Studio 2010)

I have a project in visual studio 2010. This project has the following post-build event command lines:

SET TARGET_PROJECT=TestMain
IF NOT EXIST "$(TargetDir)IceBox" (
  XCOPY /E /I /Y "$(SolutionDir)Externals\IceBox" "$(TargetDir)IceBox"
)
IF NOT EXIST "$(TargetDir)bzip2.dll" (
  COPY "$(SolutionDir)Externals\IceBox\bzip2.dll" "$(TargetDir)"
)
XCOPY /E /I /Y "$(SolutionDir)Externals\Infragistics" "$(TargetDir)"

But this commands are just used when I create a debug or a release. When I publish my project will this commands ignored. Gives it a possibility to use this commands when I publish the project?

Thanks for any help.

like image 511
Waronius Avatar asked Feb 26 '13 13:02

Waronius


People also ask

How to use post build event in Visual Studio?

In the Post-build event command line box, specify the syntax of the build event. Add a call statement before all post-build commands that run . bat files. For example, call C:\MyFile.

How do I get build command in Visual Studio?

To compile source files from within the Visual Studio IDE, choose the Build command from the Build menu. When you build project files by using the Visual Studio IDE, you can display information about the associated vbc command and its switches in the output window.

How do I open a build event in Visual Studio?

Go to Solution Explorer and right-click on the project then select Properties then go to the Build Events tab.

How do I debug a post build event in Visual Studio?

Another way is to check the bin\debug dir for 'PreBuildEvent. bat' or 'PostBuildEvent. bat' which are the file that Visual Studio creates and run during the build events, if there is an error the files remain in the output dir and you can run them manually and spot the error.


1 Answers

I recently faced a similar problem. I wanted to run a command 'only' if I published the application and not with every build.

I added a post publish task. Since I don't use MSBuild directly I modified my solution csproj file.

Example:

Solution Name: MyKillerApp

Project File name: MyKillerApp.csproj

Open the file with Notepad++ or other text editor and navigate to the end of the file and find this section(should be almost at the end):

  <PropertyGroup>
    <PreBuildEvent>
    </PreBuildEvent>
  </PropertyGroup>

Then add your postpublish task

  <PropertyGroup>
    <PreBuildEvent>
    </PreBuildEvent>
  </PropertyGroup>
  <Target Name="AfterPublish">
    <Exec Command="..\..\Documentation\DoxyGenExe\createDocs.bat" />
  </Target>

My task runs a bat file that runs Doxygen (a very nice docs creation program) and some other tasks.

You can create a bat file to run any commands is very handy

like image 149
Termiux Avatar answered Oct 04 '22 06:10

Termiux