gpt4 book ai didi

c# - 为什么.net项目有时会使用旧版本的dll?

转载 作者:行者123 更新时间:2023-11-30 16:47:11 25 4
gpt4 key购买 nike

我有一个依赖于库 Foo2 的项目 Foo1,其中 Foo2 依赖于库 Foo3。

Foo1 是 c# gui 应用程序,Foo2 是 C++/Cli 库,Foo3 是 native c++ 库

Foo2/Foo3 库的 Dll 位于单独的文件夹 Lib 中。我注意到,有时 Foo1 使用旧版本的 Foo2.dll 文件。它将 dll 从 Lib 文件夹复制到 Bin 文件夹,在那里它保存可执行文件,并使用它们。当我在 Foo3 库中进行更改时,Foo2 项目也会重建。 Dll 在 Lib 文件夹中被替换。但是它们在 Bin 文件夹中没有更新,因此主应用程序使用旧的 dll。

它来自 Foo1.csproj 文件:

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1D3976DD-23E4-4798-80A5-AFA8D34E9342}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AuthorProtoNet</RootNamespace>
<AssemblyName>AuthorProtoNet</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<!-- Predefined intermediate and output paths, defined for all configurations-->
<IntermediateOutputPath>..\..\Temp\win-$(Platform)-$(Configuration)\$(AssemblyName)\</IntermediateOutputPath>
<OutputPath>..\..\Bin\win-$(Platform)-$(Configuration)\</OutputPath>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<Reference Include="Foo2">
<HintPath>..\..\..\Lib\win-$(Platform) $(Configuration)\Foo2.dll</HintPath>
</Reference>

最佳答案

MSBuild(Visual Studio 的默认构建引擎)不会添加对非托管库和项目(例如 C++ 库或项目)的引用,因此不会将它们复制到项目的输出目录。复制非托管库的常用解决方案是使用构建后事件。生成后事件是 MSBuild 在生成项目后执行的用户配置的 DOS 命令。

您可以在项目的构建后事件编辑器中设置项目的构建后事件;您会在项目的 Properties > Build Events > Post-build event command line 中找到它。此外,MSBuild DOS 提示符可以访问所有构建变量(例如 $(Configuration)$(Platform) 等),因此根据以下配置适当的源路径和目标路径构建配置应该不是问题。在您的情况下,类似以下构建后配置(未经测试)的东西应该可以工作。

<PropertyGroup>
<PostBuildEvent>xcopy \qy ..\..\..\Lib\win-$(Platform) $(Configuration)\Foo2.dll $(OutDir)</PostBuildEvent>
</PropertyGroup>

附言构建后事件编辑器将为您生成前面的部分。不一定需要自己创建。

关于c# - 为什么.net项目有时会使用旧版本的dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39878831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com