首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在TargetPath a(cs\vb\fs)proj.user中指定$( <StartArguments> )?

如何在TargetPath a(cs\vb\fs)proj.user中指定$( <StartArguments> )?
EN

Stack Overflow用户
提问于 2012-10-07 20:06:07
回答 1查看 13.1K关注 0票数 1

我有一个Visual项目,其启动操作设置为在PowerShell中加载DLL,如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Platform)' == 'Debug|x86'">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
    <StartArguments>-NoProfile -NoExit -Command Add-Type -Path  "Foo.dll" -PassThru | Select FullName</StartArguments>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <StartAction>Program</StartAction>
    <StartProgram>c:\windows\system32\windowspowershell\v1.0\powershell.exe</StartProgram>
    <StartArguments>-NoProfile -NoExit -Command Add-Type -Path  "Foo.dll" -PassThru | Select FullName</StartArguments>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <StartProgram>C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
    <StartArguments>-NoProfile -NoExit -Command Add-Type -Path  "Foo.dll" -PassThru | Select FullName</StartArguments>
    <StartAction>Program</StartAction>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <StartProgram>c:\windows\system32\windowspowershell\v1.0\powershell.exe</StartProgram>
    <StartArguments>-NoProfile -NoExit -Command Add-Type -Path  "Foo.dll" -PassThru | Select FullName</StartArguments>
    <StartAction>Program</StartAction>
  </PropertyGroup>
</Project>

我将文件编辑如下,以消除冗余:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup '$(Platform)' == 'x86'">
    <StartProgram>C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Platform)' == 'AnyCPU' or Condition="'$(Platform)' == 'x64'">
    <StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
  </PropertyGroup>
  <PropertyGroup>
    <StartAction>Program</StartAction>
    <StartArguments>-NoProfile -NoExit -Command Add-Type -Path  "Foo.dll" -PassThru | Select FullName</StartArguments>
  </PropertyGroup>
</Project>

现在,我想将硬编码的"Foo.dll“替换为"$(TargetPath)”。但是,它的计算结果是空字符串。下面还解析为空字符串:

  • $(AssemblyName)
  • $(TargetName)$(TargetExt)
  • $(TargetFileName)

设置值<StartArguments>-NoProfile -NoExit -Command Add-Type -Path "$(Platform)" -PassThru | Select FullName</StartArguments>确实创建了命令行"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NoExit -Command Add-Type -Path "x64" -PassThru | Select FullName

EN

回答 1

Stack Overflow用户

发布于 2012-10-08 06:46:09

在所有导入指令(如<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> )之后,移动属性声明

$(TargetPath)最初是在Microsoft.Common.targets中定义的,所以在脚本中导入该文件之前,它不会包含任何值。如果您的属性是在导入之前(以及导入属性出现之前)定义的--在自顶向下的属性评估阶段,未定义的属性将被解析为空字符串。

注意:我错误地没有注意到你指的是proj*.user*文件,而不是原始的.proj文件。我不知道visual何时加载.user文件,以及加载过程中设置了哪些上下文。您可以尝试使用原始.targets文件中的定义。这是TargetDir如何在Microsoft.common.targets: Microsoft.common.targets:$(OutDir))))))</TargetDir>中定义的

如果.user文件加载时没有任何以前构建的上下文-它仍然不能正确地解析$(OutDir)。所以对于你的问题,这仍然是不完整的答案=

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12772428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档