2

我在 MSBuild 中有一个属性来表示 MSBuildProjectDirectory 上方的目录:

<PropertyGroup>
    <BuildDir>$(MSBuildProjectDirectory)\..</PRSBuildDir>
</PropertyGroup>

然后我需要使用这个属性,但我需要清理目录字符串,以便它不包含... 换句话说,我需要..评估,因此如果当前项目文件在 中C:\Test\Tom\MyDir,那么我需要一个包含字符串的属性C:\Test\Tom

我问的原因是因为我试图运行这样的命令:

msiexec /passive /i "D:\Build\2.3.84.40394\Deployment\..\Vendor\LogParser.msi"

但它抱怨通往 msi 的路径:This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.

4

4 回答 4

2

有一个ConvertToAbsolutePath 任务,有什么用?

于 2010-08-09T11:28:01.953 回答
1

我现在最好的方法如下,但我想知道是否有更好的方法..

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <BuildDir>$(MSBuildProjectDirectory)\..</BuildDir>
    </PropertyGroup>

    <Target Name="Test">
        <ItemGroup>
            <CleanBuildDir Include="$(BuildDir)" />
        </ItemGroup>

        <PropertyGroup>
            <BuildDir>%(CleanBuildDir.FullPath)</BuildDir>
        </PropertyGroup>

        <Message Text="$(BuildDir)" />
    </Target>
</Project>
于 2010-08-06T15:18:27.647 回答
1

如果您想对通配符进行评估,您应该使用 Item而不是 Property。

<ItemGroup>
  <BuildDir Include="$(MSBuildProjectDirectory)\.."/>
</ItemGroup>

<Target Name="ExecMSIExec">
  <Exec Command="msiexec /passive /i %(BuildDir.FullPath)\Vendor\LogParser.msi"/>
</Target>
于 2010-08-07T06:01:06.883 回答
1

(删除了我的答案,因为我没有看到汤姆以完全相同的方式回答!)

顺便说一句,为什么不将实际调用 msiexec 的 Exec 任务的“WorkingDirectory”属性设置为 MSI 的位置 - 这样您就不会遇到路径长度问题

于 2010-08-11T09:50:57.037 回答