MSBuild 干净目录字符串

发布于 2024-09-13 17:50:26 字数 608 浏览 4 评论 0原文

我在 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 的路径: 无法打开此安装包。验证该包是否存在并且您可以访问它,或者联系应用程序供应商以验证这是一个有效的 Windows Installer 包。

I have a property in MSBuild to represent the directory above the MSBuildProjectDirectory:

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

I need to then use this property, but I need the directory string cleaned so that it doesn't include the ... In other words I need the .. evaluated, so that if the current project file is in C:\Test\Tom\MyDir, then I need a property containing the string C:\Test\Tom.

The reason I'm asking is because I'm trying to run a command like this:

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

But it's complaining about the path to the 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半边脸i 2024-09-20 17:50:27

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

There's a ConvertToAbsolutePath task, that any use?

Saygoodbye 2024-09-20 17:50:27

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

<?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>

The best method I've got right now is below, but I was wondering if there might be a better way..

<?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>
筱果果 2024-09-20 17:50:27

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

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

<Target Name="ExecMSIExec">
  <Exec Command="msiexec /passive /i %(BuildDir.FullPath)\Vendor\LogParser.msi"/>
</Target>

If you want to have wildcard evaluated, you should use Item instead of Property.

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

<Target Name="ExecMSIExec">
  <Exec Command="msiexec /passive /i %(BuildDir.FullPath)\Vendor\LogParser.msi"/>
</Target>
橘寄 2024-09-20 17:50:27

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

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

(deleted my answer as I didn't see that Tom had answered in exactly the same way!)

By the way, why don't you set the "WorkingDirectory" attribute of the Exec task where you actually call msiexec to be the location of your MSI - that way you won't run into an path length issues

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文