![](/img/trans.png)
[英]Force to use msbuild 4.0 to compile the project in .Net 4.0 even when .Net fw. 4.5 is installed
[英]Autobuild a .NET 4.5 project when I build a .NET 4.0 project? It does NOT need to be referenced
我有一個使用.NET 4.0構建的C#項目,該項目在通過.NET 4.5構建的項目上具有軟/間接依賴關系(通過反射)。
我試圖找出my40project.csproj
中的條目,該條目將在構建my45project.csproj
時構建my40project.csproj
。 我不需要引用在所有4.0項目所產生的DLL,雖然。
我在my40project.csproj
有以下條目:
<ProjectReference Include="$(RootDir)\path\to\project\my45project.csproj">
<Project>{some guid}</Project>
<Name>my45project</Name>
</ProjectReference>
但是,這會產生以下錯誤消息:
"D:\path\to\project\my40project.csproj" (default target) (1) ->
(ResolveAssemblyReferences target) ->
error SCP3000: A non-baseline warning (MSB3274) was encountered: The primary reference "my45project.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
有誰知道我該怎么解決? 如果這是重復的,我深表歉意。 搜索時發現的問題直接涉及使用4.0項目中的結果.NET 4.5 DLL,我不需要這樣做(我只需要構建它)
謝謝!
由於不必直接引用項目,因此可以選擇使用Post Build事件復制dll。 基本上,您將兩個項目都放在一個解決方案中(不要互相引用),然后將4.5項目的Post Build事件配置為包括以下內容
copy /Y "source.dll" "destination"
這將確保您的4.0項目將要使用的dll始終是每個完整解決方案構建之后的最新版本。
編輯:解決方案文件
Microsoft Visual Studio解決方案文件,格式版本為12.00
Visual Studio 14 VisualStudioVersion = 14.0.23107.0最小VisualStudioVersion = 10.0.40219.1
Project(“ {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}”)=“ Test”,“ Test \\ Test.csproj”,“ {F6B2FFFE-AEBD-4D47-99F6-B4EFD200E50A}”
EndProject
Project(“ {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}”)=“ test2”,“ test2 \\ test2.csproj”,“ {AD7D893B-7113-4E96-8CC1-0321E576B2A2}”
EndProject
項目1目標:
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
項目2目標:
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
並建立解決方案
1> ------重建全部開始:項目:測試,配置:調試任何CPU ------
2> ------重建全部開始:項目:test2,配置:調試任何CPU ------
1>測試-> ------ \\ Test.exe
2> test2-> ------ \\ test2.exe
==========全部重建:2個成功,0個失敗,0個跳過===========
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.