简体   繁体   中英

Change the referenced dll in a SSIS script task at build / deploy or runtime

Recently I have added all of our SSIS projects into a continuous integration pipeline. The projects are built using MSBuild in TeamCity, packaged and pushed to a nuget feed. We deploy them using Octopus and some hand cranked PowerShell built on the back os SQL server management objects (SMO). It all works, with the exception of one project. The project in question contains some script tasks which reference an external assembly. That assembly is built in the same pipeline and its assembly version numbers are updated by part of the process. The problem lies in the fact that the SSIS project now references a strong named dll in the GAC which does not exist because the version numbers have changed.

Does anyone know of a way to either updated the reference at build time on the CI server or override the version number at the point of deployment?

I know this post is quite old but it has been viewed a lot so here's a solution I have found.

You need to include a 'targets' file for the build.

Here's an example Targets file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <E10BOs>C:\Integrations\E10 Uplifts\Epicor 10.2.600.3</E10BOs>
    </PropertyGroup>
    <Target Name="BeforeResolveReferences">
        <CreateProperty Value="$(E10BOs);$(AssemblySearchPaths)">
            <Output TaskParameter="Value" PropertyName="AssemblySearchPaths" />
        </CreateProperty>
    </Target>
</Project>

The property group E10BOS (and there can be more than 1) then defines the path to the dll's of the version you want to build against.

It needs to be saved as myTargetsFile.targets

Then in a regular VS project you could add this line to the project file (outside of VS in notepad)

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), myTargetsFile.targets))\myTargetsFile.targets" />
</Project>

This uses GetDirectoryNameOfFileAbove to search up the folder tree until it finds you targets file and then imports it. Very useful if you have a lot of different projects all requiring a version change and you don't have to figure out any relative paths!

In SSIS however this doesn't seem to work. What does is hard-wiring the path to the targets file in the package .dtsx file, again edit it in notepad and add the following line (you will probably see the csharp entry near the end of the project tag as before:

<Import Project="C:\Integrations\E10 Uplifts\Epicor 10.2.600.3\myTargetsFile.targets" />

This will pass through the information of the project references into the scripts.

Then with all of you projects using a targets file changing the version is done by changing the path to the version folder you want them to use.

Hope that helps?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM