两个 Visual Studio 构建后事件问题和 MSBuild

发布于 2024-07-25 18:10:09 字数 1607 浏览 4 评论 0原文

我有两个问题:Visual Studio 2008 和构建后事件。

1)如何动态列出 msbuild.exe 完整路径,以供构建后事件调用? 目前,我有以下内容(顺便说一句,效果很好):-

C:\Windows\Microsoft.NET\Framework64\v3.5\msbuild.exe 
    "$(ProjectDir)MSBuild\MSBuildSettings.xml"

..但这只有在您有 x64 位环境时才有效。 有没有办法使用一些内置的魔法设置? 例如。 $(MsBuildPath)msbuild.exe“blah....xml” ??

2)我的msbuild任务做了一些事情,然后生成一个txt文件作为输出。 我在 msbuild xml 文件中定义输出路径。

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">
    <UsingTask TaskName="CustomTask" AssemblyFile="MyAssembly.dll"/>
    <Target>
        <CustomTask
           ...
           OutputFile="Foo.txt"
        />
    <Target>
</Project>

我如何将真实的输出文件夹传递到 msbuild 文件? 我尝试过...

OutputFile="$(OutDir)Foo.txt"

但失败了:(

干杯!

更新#1 - 回答第二个问题..

我已经找到了一种方法来回答第二个问题——但不确定它是否是最好的..所以我'我愿意接受其他想法 :)

XML 文件更改 :: 添加一个属性组,如果没有外部参数传递给 msbuild.exe 可执行文件,则设置内部变量名称。

    <PropertyGroup>
        <OutputFile Condition=" '$(OutputFile)'=='' ">
            ..\SomeFolder\Foo.txt</OutputFile>
    </PropertyGroup>

    <Target>
        <CustomTask
           ...
           OutputFile="$(OutputFile)"
        />
    <Target>
</Project>

现在,像...这样调用 msbuild 可执行文件,

msbuild.exe "C:\Temp Foo\Blah\MsbuildSettings" /p:OutputFile="C:\Folder 1\Folder 2\blah\"

这样就可以了:)

I have two questions re: visual studio 2008 and post-build events.

1) How do i dynamically list the msbuild.exe full path, to be called by the post-build event? Currently, i have the following (which works beautifully, btw):-

C:\Windows\Microsoft.NET\Framework64\v3.5\msbuild.exe 
    "$(ProjectDir)MSBuild\MSBuildSettings.xml"

.. but that would only work if u have a x64 bit environment. Is there a way to use some built in magic setting? eg. $(MsBuildPath)msbuild.exe "blah....xml" ??

2) My msbuild task does some stuff then generates a txt file as the output. I define the output path in the msbuild xml file as such..

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">
    <UsingTask TaskName="CustomTask" AssemblyFile="MyAssembly.dll"/>
    <Target>
        <CustomTask
           ...
           OutputFile="Foo.txt"
        />
    <Target>
</Project>

How can i pass in the real output folder, to the msbuild file? I tried...

OutputFile="$(OutDir)Foo.txt"

but that failed :(

Cheers!

Update #1 - Answer to the second question..

I've figured out a way to answer the second question -- not sure if it's the best one though .. so I'm open to other ideas :)

XML file changes :: add a property group that sets the internal variable name IF no outside arguments were passed to the msbuild.exe executable.

    <PropertyGroup>
        <OutputFile Condition=" '$(OutputFile)'=='' ">
            ..\SomeFolder\Foo.txt</OutputFile>
    </PropertyGroup>

    <Target>
        <CustomTask
           ...
           OutputFile="$(OutputFile)"
        />
    <Target>
</Project>

Now, call the msbuild executable like ...

msbuild.exe "C:\Temp Foo\Blah\MsbuildSettings" /p:OutputFile="C:\Folder 1\Folder 2\blah\"

and that works :)

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

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

发布评论

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

评论(2

悲念泪 2024-08-01 18:10:09

对于问题 1,使用属性 MSBuildBinPath

对于问题2,使用属性OutputPath(C#或VB项目)

OutputFile="$(OutputPath)Foo.txt"

For question 1, use property MSBuildBinPath

For question 2, use property OutputPath (C# or VB projects)

OutputFile="$(OutputPath)Foo.txt"
地狱即天堂 2024-08-01 18:10:09

您可以将自定义任务放入 vbprojcsproj 如果是 ac# 项目)文件中,然后让构建后事件使用 VS 定义的 MSBuild 变量。 我正在突然想到这个过程,所以请耐心等待,哈哈。

  1. 在 Visual Studio 中,卸载要用于生成后事件的项目,然后右键单击卸载的项目节点并选择“编辑...”。
  2. UsingTask 放在顶部,就像您所拥有的一样。
  3. 重新加载项目,打开项目属性并在那里编辑构建后事件。
  4. 您现在应该能够访问所有这些漂亮的变量,并将它们添加到您的自定义任务中。

项目文件本身就是 MSBuild 脚本,允许您执行各种漂亮的 MSBuild 脚本技巧。

编辑:抱歉,对于您提出的第一个问题,我没有答案。

You could put your custom task inside the vbproj (csproj if it's a c# project) file and then have the post-build event use the VS-defined MSBuild variables. I'm thinking of this process off the top of my head, so bear with me on this, lol.

  1. In Visual Studio, unload the project you want to have the post-build event with, and then right-click on the unloaded project node and select 'Edit...'.
  2. Put the UsingTask at the top, just like what you have.
  3. Reload the project, and open up the project properties and go to edit the post-build event there.
  4. You should be able to access all those nifty variables now, and add them to your custom task.

Project files are MSBuild scripts in themselves, allowing you to do all sorts of nifty MSBuild scripting tricks.

Edit: Sorry, I don't have an answer for the first question you asked.

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