How do I make msbuild find .Net assemblies when using a custom task (UsingTask)>

微笑、不失礼 提交于 2019-12-12 04:21:14

问题


I've built a custom msbuild task based on the old CodePlex project:

http://sqlsrvintegrationsrv.codeplex.com/SourceControl/latest#main/SSISMSBuild/Project/Microsoft.SqlServer.IntegrationServices.Build.csproj

After finally getting this to build in VS 2015 (using the SQL Server 2016 SMSS assemblies) I can use the compiled project DLL to build SSIS projects.

However, I can only get the SSIS project to build (e.g. using a project file such as at https://speaksql.wordpress.com/2013/06/07/a-journey-to-db-deployment-automaton-ssis-build-using-msbuild/) when I copy the assemblies (the custom task DLL and the dependences from SMSS) into a copy of the msbuild bin directory.

Is there any way to direct Msbuild to look in a specific path? I'd rather not add assembles to the GAC if possible.

I've read any web articles and posts but they mostly refer to C# .csproj projects and they refer to setting AssemblySearchPaths and ReferencePath. As this isn't a C# project file I can't use these.

This issue is only occurring on one of my machines (Windows Server 2012). Thing seem to work fine on my Windows 10 machine :(

I can see other people have also seen this issue. E.g.:- MsBuild does not look in the good directory for custom task's second-level dependencies

Any help would be greatly appreciated!


回答1:


The <UsingTask> directive's AssemblyFile attribute allows you to specify the full path to the assembly you want to load.

This is usually done relative to the location of the file that wants to use a particular task. e.g. if you build a NuGet package that contains a task, you would usually have a build/{packageId}.targets file and for example an tools/net46/sometasks.dll that contains the needed tasks. The .targets file would then use:

<UsingTask TaskName="MyCustomTask" AssemblyFile="$(MSBuildThisFileDirectory)..\tools\net46\sometasks.dll" />

If the task dll also references other assemblies, they need to be located in the same directory as the assembly in order to be discovered.



来源:https://stackoverflow.com/questions/44976387/how-do-i-make-msbuild-find-net-assemblies-when-using-a-custom-task-usingtask

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!