在开发中轻松覆盖NuGet DLL(VS 2015) [英] Easily override NuGet DLL in development (VS 2015)

查看:121
本文介绍了在开发中轻松覆盖NuGet DLL(VS 2015)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在VS 2015中提供了3个包含C#项目的解决方案.其中一个创建一个NuGet包,另两个创建该NuGet包中的DLL. (该DLL包含应用程序两个部分之间的接口.)TeamCity构建服务器将构建DLL和NuGet程序包,并自动设置其版本.

We have 3 solutions in VS 2015 containing C# projects. One of those creates a NuGet package and the other 2 reference a DLL from that NuGet package. (The DLL contains the interface between two parts of an application.) A TeamCity build server builds the DLL and the NuGet package, automatically setting its version.

在开发中,我希望能够轻松测试对DLL的更改,而无需提交更改并等待构建包.最好的方法是什么?理想情况下,我想说:如果C:\Build\My.dll存在,则不管其版本如何使用它,否则使用MyDLL NuGet package version 1.2.3.4.有什么方法可以指定它并使它存活" NuGet升级吗?

In development I want to be able to easily test changes to the DLL without committing them and waiting for the package to be built. What's the best way to do this? Ideally I want to say: if C:\Build\My.dll exists then use it regardless of its version, otherwise use version 1.2.3.4 of the MyDLL NuGet package. Is there any way to specify that and have it "survive" NuGet upgrades?

我试图临时删除对该DLL的引用,并直接添加对我想要的版本的引用,但是问题是,在许多项目中都引用了它,并且对所有这些项目都这样做很麻烦.

I tried temporarily deleting the reference to that DLL and adding a reference directly to the version I want, but the problem is that it's referenced in many projects and doing this for all of them is quite a hassle.

推荐答案

看起来可以通过删除现有的NuGet引用在BeforeBuild步骤中完成.这样,NuGet参考项本身是不变的,可以在升级过程中自由地由NuGet替换,但是在构建过程中会使用我的DLL版本(如果存在).

Looks like it can be done in the BeforeBuild step by removing the existing NuGet reference. This way, the NuGet reference item itself is unchanged and can be freely replaced by NuGet during upgrades, but during the build my version of the DLL gets used (if it exists).

无论版本如何,删除引用都需要一点技巧.

It also takes a slight hack to remove the reference regardless of version.

  <Target Name="BeforeBuild">
    <!-- Override NuGet package with a local copy in dev, if available -->
    <PropertyGroup>
        <ReplacementLocalDllPath>Some\Path\My.dll</ReplacementLocalDllPath>
    </PropertyGroup>
    <ItemGroup Condition="Exists($(ReplacementLocalDllPath))">
      <!-- Remove any version of the DLL to be replaced -->
      <ReferenceToBeRemoved Include="@(Reference)" Condition="$([System.String]::Copy(&quot;%(Reference.Filename)&quot;).StartsWith('My'))" />
      <Reference Remove="@(ReferenceToBeRemoved)" />
      <!-- Add the local DLL, ignoring its version -->
      <Reference Include="My, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
        <SpecificVersion>False</SpecificVersion>
        <HintPath>$(ReplacementLocalDllPath)</HintPath>
      </Reference>
    </ItemGroup>
  </Target>

这篇关于在开发中轻松覆盖NuGet DLL(VS 2015)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆