msbuild 脚本中的其他路径
如何为 MSBuild 任务指定其他程序集引用路径?
到目前为止,我有以下脚本,但无法弄清楚如何指定其他搜索路径。
<ItemGroup>
<ProjectsToBuild Include="..\Main\Main.sln" />
</ItemGroup>
<!-- The follwing paths should be added to reference search paths for the build tasks -->
<ItemGroup>
<MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib1" />
<MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib2" />
</ItemGroup>
<MSBuild
Projects="@(ProjectsToBuild)"
Properties="Configuration=Debug;OutputPath=$(BuildOutputPath)">
</MSBuild>
更新:
请显示一个完整的工作脚本,该脚本调用原始项目,例如具有多个附加参考路径的 SLN。
没有关于如何改进项目结构的建议。 我知道如何建造一个好的结构,但现在的任务是建造一个现有的垃圾。
How to specify additional assembly reference paths for the MSBuild tasks?
I have following script so far, but can't figure out how to specify additional search paths.
<ItemGroup>
<ProjectsToBuild Include="..\Main\Main.sln" />
</ItemGroup>
<!-- The follwing paths should be added to reference search paths for the build tasks -->
<ItemGroup>
<MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib1" />
<MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib2" />
</ItemGroup>
<MSBuild
Projects="@(ProjectsToBuild)"
Properties="Configuration=Debug;OutputPath=$(BuildOutputPath)">
</MSBuild>
UPDATE:
Please show one complete working script which invokes original project, such as an SLN with multiple additional reference paths.
No suggestions on how to improve the project structure please.
I know how to build a good structure, but now it's the task of building an existing piece of crap.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我终于想出了如何做到这一点:
I have finaly figured out how to do it:
您要修改的属性是AssemblySearchPaths。有关详细信息,请参阅ResolveAssemblyReference 任务。
使用项目组,如您的示例所示,它看起来像:
查看 %WINDIR%\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets,您可以看到 ResolveAssemblyReference 任务 作为 ResolveAssemblyReferences目标。因此,您希望新添加的目标在执行 ResolveAssemblyReferences 之前修改 AssemblySearchPaths 属性。
The property you want to modify is AssemblySearchPaths. See the ResolveAssemblyReference task more information.
Making use of item groups, as in your example, it would look like:
Looking in %WINDIR%\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets, you can see that the ResolveAssemblyReference Task is executed as part of the ResolveAssemblyReferences target. Thus, you want the newly added target to modify the AssemblySearchPaths property before ResolveAssemblyReferences is executed.
您已经声明您希望能够修改程序集搜索路径而不直接修改项目文件。为了满足该要求,您需要设置一个将覆盖 AssemblySearchPaths 的环境变量。使用此技术,您将需要提供解决方案中所有项目使用的每个程序集引用路径。 (修改项目或项目副本会更容易。请参阅最终评论。)
一种技术是创建一个批处理文件,该批处理文件在设置环境变量时运行脚本:
另一种方法是在自定义 msbuild 文件中定义 PropertyGroup(否则称为完成这项工作所需的“钩子”):
现在,如果是我,并且由于某种无法解释的原因,我无法修改项目文件以包含我将要构建的更新的引用,我会复制项目文件,将它们加载到 IDE 中,并更正我副本中的引用。同步项目变成了一个简单的差异/合并操作,使用 Mercurial 等现代工具可以自动完成(我确信 Clearcase 也可以管理它)。
You've stated that you want to be able to modify the assembly search paths without modifying the project files directly. In order to accomplish that requirement you need to set an environment variable that will override the AssemblySearchPaths. With this technique you will need to provide every assembly reference path used by all the projects in the solutions. (Modifying the projects or copies of the projects would be easier. See final comments.)
One technique is to create a batch file that runs your script at sets the environment variable:
Another way is to define a PropertyGroup in your custom msbuild file (otherwise known as the "hook" needed to make this work):
Now if it were me, and for whatever unexplained reason I couldn't modify the project files to include the updated references that I am going to build with, I would make copies of the project files, load them into the IDE, and correct the references in my copies. Synching the projects becomes a simple diff/merge operation which is automatic with modern tools like mercurial (heck I'm sure clearcase could manage it too).
...并且请记住,您不需要为此使用目标,您可以使用项目范围的属性或项目,因为...
...如果您确实需要在目标中执行此操作来拾取路径从动态填充的项目组中,使用内联属性,而不是 CreateProperty 任务(如果您没有陷入 v2.0)
...and remember that you don't need to use a target for this, you can use project-scoped properties or items, as...
...and if you do need to do this in a target to pick up paths from a dynamically populated item group, use inline properties, not the CreateProperty task (if you are not stuck in v2.0)