MSBUILD 14.0 Visual Studio 2015 CustomBuild Command 环境不包含 SetEnv 的结果,即使 Exec 包含 [英] MSBUILD 14.0 Visual Studio 2015 CustomBuild Command environment does not contain the result of a SetEnv even though Exec does

查看:49
本文介绍了MSBUILD 14.0 Visual Studio 2015 CustomBuild Command 环境不包含 SetEnv 的结果,即使 Exec 包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 CoApp 创建了一个 nuget 包来打包一些代码生成器(二进制文件).我希望能够在 msbuild custombuild 步骤中使用这些代码生成器来生成代码

I have used CoApp to create a nuget package to package some code generators (binaries). I want to be able to use these code generators in a msbuild custombuild step to generate the code

我有一个定义以下内容的目标文件(使用 CoApp)

I have a targets file that defines the following (using CoApp)

<SetEnv Condition="'$(Platform.ToLower())' == 'x64' And '$(PlatformToolset.ToLower())' == 'v100' And ( $(Configuration.ToLower().IndexOf('debug')) == -1 )" Name="PATH" Prefix="true" Value="$(MSBuildThisFileDirectory)../..//build/native/bin/x64\v100\Release;">
  <Output TaskParameter="OutputEnvironmentVariable" PropertyName="PATH" />
</SetEnv>

包含此代码段的目标文件像这样导入到项目(vcxproj 文件)中

The targets file containing this snippet is imported like so into a project (vcxproj file)

<Import Project="..\packages\habitat.id.redist.1.0.0.5\build\native\habitat.id.redist.targets" Condition="Exists('packages\habitat.id.1.0.0.1\build\native\habitat.id.targets')" />

项目内

<Exec Command="echo %PATH%"/>

返回所需的结果,即采用以下形式的结果<代码>../..//build/native/bin/x64\v100\Release;C:\

returns the desired outcome i.e. that which takes the form ../..//build/native/bin/x64\v100\Release;C:\

所以我可以调用我想从项目中运行的可执行文件.(除了与 custombuild 命令步骤不同,没有 outputs 的概念.因此增量构建将不起作用)

so I can call the executable that I want to run from the project. (except for unlike a custombuild command step there is no concept of outputs. So incremental builds will thence not work)

然而

<CustomBuild Include="..\directory\filename">
  <FileType>Document</FileType>
  <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  echo $(PATH)
</Command>

不包含我想要的通过 SetEnv 设置的路径.

does not contain the path that I want that was set through the SetEnv.

我想这样做是为了我可以调用在自定义构建步骤中通过 nuget 打包的代码生成器.

I want to do this so I can call code generators that were packaged via nuget during a custom build step.

我了解 custombuild 中的 command 贯穿/在新的 cmd 中运行,并且环境是通过设置的用户或系统环境继承的.此外,我可以使用 /p:useenv 启动 Msbuild,从而泵出我想要的任何环境.这,使用 /p:useenv,在我看来相当于硬编码路径 - 提前知道它.

I understand that the command inside a custombuild runs through/in a new cmd and that the environment is inherited via the user or system env's that were set. Also that I can start Msbuild using /p:useenv , and hence pump any environment that I would like. This, using /p:useenv, in my opinion amounts to hard coding the path - knowing it ahead of time.

我希望能够更新我的包并运行,即我希望项目管理路径,因为它是在导入的目标文件中定义的.

I want to be able to update my packages and run i.e. I want the project to manage the path given that it is defined in the target file that is imported.

推荐答案

看起来 C++ 在支持二进制文件的包更新之前还有一些路要走.头文件(ClCompile > AdditionalIncludeDirectories)和库(Link > Additionaldependencies)很好

Looks like C++ has a little ways to go until they can support package updates for binaries. The headers (ClCompile > AdditionalIncludeDirectories) and libs (Link > Additionaldependencies) are fine

我想继续使用自定义构建,因为它通过标准的 Visual Studio 属性表公开,自定义目标不是(直到您自定义属性表因此引入了一些不是每个人都熟悉的东西,会忘记安装然后抱怨)所以我希望得到一个产品级别的解决方案,该解决方案将通过下一次产品更新来实现.这看起来不太可能

I wanted to continue to use the custom build because it is exposed through the standard visual studio property sheet, a custom target is not (until you customize the property sheet hence introducing something that not everyone is familiar with, will forget to install and then complain) So I was hoping to get a product level solution that would come through the next product update. That looks unlikely

我希望继续使用环境变量方法,因为这是 CoApp 为它为 C++ 二进制文件创建的 nuget 包所做的方式.更改目标文件很容易.(不使用 CoApp 的 Write-NugetPackage,而是使用 nuget pack)

I was looking to continue to use the environment variable approach because that's the way CoApp does it for nuget package it creates for C++ binaries. It's easy enough to change the targets file. (Not using CoApp's Write-NugetPackage but use nuget pack instead)

custombuild 命令不会像这样扩展 msbuild 属性集<代码>$(MSBuildThisFileDirectory)../..//build/native/bin/x64\v90\Release并使用像<代码>$(HabitatBindir)aemcomp.exe -nonotice -mlf -dll %(Identity)Target-Exec-Property 是我能想到的最佳组合

A custombuild command does not expand msbuild properties set like $(MSBuildThisFileDirectory)../..//build/native/bin/x64\v90\Release and used like $(HabitatBindir)aemcomp.exe -nonotice -mlf -dll %(Identity) The Target-Exec-Property is the best combination I could come up with

当我弄清楚如何发布大量双引号和单引号文本时,将在下面发布代码

Will post code below when I figure out how to post heavily double quoted and single quoted text

这篇关于MSBUILD 14.0 Visual Studio 2015 CustomBuild Command 环境不包含 SetEnv 的结果,即使 Exec 包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆