开发者

Can I just execute pre and post built for a project within a visual studio solution?

I want to add some project within VS solution but it isn't .net. I'd like to use pre and post build to run some custom command can I deacti开发者_JAVA百科vate build for this project but still have pre and post build ?


This can be accomplished on the command-line via MSBuild by specifying your own custom Target instead of a DLL or EXE. However, this will make it difficult to use within Visual Studio.

The easiest way I can think of is to create a separate project within your solution with only the required input files and no source files. You can insert your custom pre-build and post-build events which will run with the build, although the build itself creates and empty output file. You could even add a task to the post-build step to delete the empty output. A minimal .csproj file might look like:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ProjectGuid>{35E9C892-375D-4372-8A02-62E6D425A373}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>CustomBuild</RootNamespace>
    <AssemblyName>CustomBuild</AssemblyName>
  </PropertyGroup>
  <ItemGroup>
    <None Include="customFile.txt" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <PropertyGroup>
    <PreBuildEvent>type  "$(ProjectDir)customFile.txt" &gt; "$(TargetDir)intermediate.txt"</PreBuildEvent>
  </PropertyGroup>
  <PropertyGroup>
    <PostBuildEvent>del "$(TargetPath)"
type "$(TargetDir)intermediate.txt" &gt;&gt; "$(TargetDir)output.txt"</PostBuildEvent>
  </PropertyGroup>
</Project>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜