两个 Visual Studio 构建后事件问题和 MSBuild
我有两个问题: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于问题 1,使用属性 MSBuildBinPath
对于问题2,使用属性OutputPath(C#或VB项目)
For question 1, use property MSBuildBinPath
For question 2, use property OutputPath (C# or VB projects)
您可以将自定义任务放入 vbproj(csproj 如果是 ac# 项目)文件中,然后让构建后事件使用 VS 定义的 MSBuild 变量。 我正在突然想到这个过程,所以请耐心等待,哈哈。
项目文件本身就是 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.
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.