开发者

VCBuild task in MSBuild - change outputpath

I'm attempting to write an automated build for one of our products, and I've hit up against a wall for some of our VC++ projects: I need to be able to set the output path to where the assemblies will be copied once its done.

Here is a makeshift msbuild file:

<Project DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="3.5">
 <Target Name="Build">
   <VCBuild Projects="C:\src\SomeProject\SomeProject.vcproj"
            ToolPath="C:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages"
          开发者_开发百科  Configuration="Debug" />
 </Target>
</Project>

Stijn's Answer:

I thought I'd use this space to clarify how I personally used Stijn's answer to solve this. He has some code in his MSBuild file that writes the vsprops file for him. I decided to take a simpler approach and just write the file manually.

I created this file, called build.vsprops (my output path is V:)

<?xml version="1.0"?>
<VisualStudioPropertySheet ProjectType="Visual C++"
                           Version="8.00"
                           Name="Overrides"
                           OutputDirectory="V:\">
  <Tool Name="VCCLCompilerTool"
        AdditionalUsingDirectories="V:\" />
</VisualStudioPropertySheet>

Then I edited my MSBuild file to add the Override parameter:

<Project DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="3.5">
 <Target Name="Build">
   <VCBuild Projects="C:\src\SomeProject\SomeProject.vcproj"
            ToolPath="C:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages"
            Configuration="Debug"
            Override="$(MSBuildProjectDirectory)\build.vsprops" />
 </Target>
</Project>


have a look at the Override parameter for the VCBuild task. Basically you specify a property sheet which you can use to override whatever property you want (it has the same effect as adding a property sheet to the top of the list in a project within VS). You could even generate the override file using the WriteLinesToFile task.

Example:

<PropertyGroup>
  <VCOverridesFile Condition=" '$(VCOverridesFile)'=='' ">overrides.vsprops</VCOverridesFile>
  <VCOverridesOpen>%3C?xml version=%221.0%22?%3E%0D%0A%3CVisualStudioPropertySheet ProjectType=%22Visual C++%22 Version=%228.00%22 Name=%22My Overrides%22%3E</VCOverridesOpen>
  <VCOverridesClose>%3C/VisualStudioPropertySheet%3E</VCOverridesClose>
  <MyOutPath>&lt;Tool Name="VCLinkerTool" OutputFile ="c:\my.exe"/&gt;</MyOutPath>
</PropertyGroup>

<Target Name="WriteOverridesFile">
  <WriteLinesToFile
    File="$(VCOverridesFile)"
    Lines="$(VCOverridesOpen);$(AdditionalVCOverrides);$(VCOverridesClose)"
    Overwrite="true" />
</Target>

Then pass $(VCOverridesFile) to the Override property and make sure your VCBuild Task DependsOnTarget WriteOverridesFile.


Doing it the dirty way you can pass output directory path through command line arguments of msbuild.

msbuild yourProject /p:OutDir=yourPath

Although I suspect, there should be the better way to accomplish the task. The main idea is to set 'OutDir' property in such a way that it will not be overriden by your SomeProject.vcproj


if you are using Azure DevOps and needs to create a YAML do build a .net framework (vintage[old])

- task: VSBuild@1
  inputs:
    solution: '**\*.sln'
    msbuildArgs: '/p:DeployOnBuild=true /p:SkipInvalidConfigurations=false /p:OutDir="$(System.DefaultWorkingDirectory)\publish_output"'
    platform: 'Any CPU'
    configuration: 'Release'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜