Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在多个项目中引用公共二进制文件_C#_.net - Fatal编程技术网

C# 在多个项目中引用公共二进制文件

C# 在多个项目中引用公共二进制文件,c#,.net,C#,.net,我有一个第三方DLL,我需要在解决方案中的多个c#项目中引用它 现参考如下 <Reference Include="Contoso.App, Version=4.0.5.0, Culture=neutral, PublicKeyToken=xxxxxxxx, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\Third

我有一个第三方DLL,我需要在解决方案中的多个c#项目中引用它

现参考如下

 <Reference Include="Contoso.App, Version=4.0.5.0, Culture=neutral, PublicKeyToken=xxxxxxxx, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
   <HintPath>..\ThirdParty\Contoso\4.0.5.0\Contoso.App.dll</HintPath>
  </Reference>
 <Reference Include="Contoso.App, Culture=neutral, PublicKeyToken=xxxxxxxx, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
   <HintPath>..\ThirdParty\Contoso\5.0\Contoso.App.dll</HintPath>
  </Reference>
我必须去更新我的40个项目,如下所示

 <Reference Include="Contoso.App, Version=4.0.5.0, Culture=neutral, PublicKeyToken=xxxxxxxx, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
   <HintPath>..\ThirdParty\Contoso\4.0.5.0\Contoso.App.dll</HintPath>
  </Reference>
 <Reference Include="Contoso.App, Culture=neutral, PublicKeyToken=xxxxxxxx, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
   <HintPath>..\ThirdParty\Contoso\5.0\Contoso.App.dll</HintPath>
  </Reference>

假的
..\ThirdParty\Contoso\5.0\Contoso.App.dll
是否有更好的方法来管理DLL的版本更改

我可以在解决方案中创建单个变量并在所有项目中重用它吗

您团队的其他成员可以访问。 见答案

tl;dr

  • 开放视觉工作室
  • 创建新的空Web项目
  • 添加Nuget.Server包
    • 包管理器控制台:安装包numget.server
    • 覆盖web.config:是
  • 打开Web.config
  • 设置应用程序设置
    • 包裹路径:nuget将坐在哪里
  • 初始化:

    nuget初始化c:\source c:\localnuget

  • 推送:

    nuget push{package file}-s{apikey}


为了增加TriV注释的灵活性,您可以定义一个环境变量(例如CONTOSO_版本),并在预构建事件命令中使用它,使用$CONTOSO_版本将DLL复制到bin文件夹(或您引用的任何地方)。通过这种方式,您可以通过env变量前后更改引用的DLL版本。确保它是其他人依赖的项目的预构建事件(或者为解决方案范围的预构建事件创建一个其他人依赖的虚拟项目)

私有NuGet存储库是完美的,但需要太多更改。一种更简单的方法是创建一个公共项目,并让其他项目引用该公共项目

  • 普通道具。最好使用解决方案相对路径,而不是

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
        <Reference Include="Contoso.App, Culture=neutral, PublicKeyToken=xxxxxxxx, processorArchitecture=MSIL">
          <HintPath>..\ThirdParty\Contoso\5.0\Contoso.App.dll</HintPath>
        </Reference>
      </ItemGroup>
    </Project>
    
    
    ..\ThirdParty\Contoso\5.0\Contoso.App.dll
    
  • 在其他项目中导入它

    <Import Project="<MySolutionPath>\common.props"/>
    
    
    

  • 在common.props中进行更改后,VS中可能会出现生成错误,因为引用会立即更新。首先通过命令行msbuild.exe验证它。

    您是在解决方案中的所有项目中使用它,还是它只是一个子集?实际上不是所有项目。我有大约70个解决方案项目。其中40个引用了DLL。为什么不使用
    \ThirdParty\Contoso\CurrentVersion\Contoso.App.DLL
    作为路径,并将DLL版本5.0复制到其中。您不能使用nuget包吗?@TriV您的解决方案将无法工作,因为我还必须在引用节点中更新版本。查看我的最新编辑。