Hi and thanks in advance.
I'm using TFS build 2013 (team services, not on premise) to build my solution. After creating a new C++ project in the solution I'm unable to build successfully.
The error I'm getting on the build machine is:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): An error has occurred during compilation. error CS1705: Assembly 'Microsoft.Build.Utilities.Core,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' uses 'Microsoft.Build.Framework,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher
version than referenced assembly 'Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): The "SetEnvironmentVariable" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name
of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask
interface. 3.) The task is correctly declared with <UsingTask> in the project file, or
in the *.tasks files located in the "C:\Program Files (x86)\MSBuild\14.0\bin\amd64" directory.
I've red about error CS1705 on the internet but I still don't understand why I get this error - the project is an empty project which has no references what so ever and no other project reference it either.
I'm targeting .NET framework 4.6.1 on all my C# projects and in my build definition I'm adding these msbuild arguments: /tv:14.0 /p:VisualStudioVersion=14.0 hence it uses the 2015's version of the c# compiler.
The target platform for this C++ project is VS 2015 (v140) as follows:
C++ project configuration
Needless to say that when I'm removing this project from the list of project to build (configuration manager) - the solution builds successfully.
Any help/clue would be greatly appreciated!
The problem was something other than what I thought it was. Seems it's got something to do with CodeAnalysis and some environment variable related to it.
In my build definition I'm disabling CodeAnalysis and even inside the C++ project properties It's explicitly disabled. After I commented out some attributes on the "SetCABuildNativeEnvironmentVariables" target inside this file on the build machine:
"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets"
The problem disappered.
This is a nasty workaround however since I'm not fully aware of what's really happening.
Thanks a lot anyways!
Seems there are something still point to "Microsoft.Build.Framework, Version=12.0.0.0"
The /tv:14.0 command argument doesn't work as expected. See:
BuildActivity ignores ToolsVersion
As a workaround, you need to customize the build process template:
Open the template in Visual Studio and find the Run MSBuild for
Project MSBuild activity.
Set ToolVersion to "14.0".
Set ToolPath to target to MSBuild14 (by default: "C:\Program Files
(x86)\MSBuild\14.0\Bin").
Check in this build process template and re-queue the build.
You can also refer the answer from Marson in TFS 2013 building .NET 4.6 / C# 6.0
Related
We have a fairly large solution containing a mix of C++/CLI and C# projects using MFC and Winforms controls to build the UI. Several MFC dialogs in the app make use of a CWinFormsControl from afxwinforms.h to embed WinForms controls inside them, currently everything targets .NET48 and works fine. We are trying to update everything to .NET6.0 and everything seems OK except the one project that includes afxwinforms.h.
The project settings are:
Common Language Runtime Support: .NET Core Runtime Support(/clr:netcore)
.NET Core Target Framework: net6.0-windows (I have tried just net6.0, net5.0...)
Platform Toolset: Visual Studio 2022 (v143)
We include <afxwinforms.h> amongst several other afx includes in a precompiled header and the compiler gives this error building our stdafx.h:
C:\Program Files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\atlmfc\include\afxwinforms.h(30,8):
fatal error C1107: could not find assembly 'System.Windows.Forms.dll':
please specify the assembly search path using /AI or by setting the
LIBPATH environment variable
From some searching on the internet I found and attempted to pass the following directories using the Additional #using Directories property of the project:
C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App\6.0.0\
C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.0\ref\net6.0\
C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\6.0.0\
Any of those paths seems to sort out the above compiler error, and intellisense seems to recognise everything in afxwinforms.h too. However, the compiler starts giving warnings such as:
C:\Program Files (x86)\Windows
Kits\10\Include\10.0.22000.0\um\objidl.h(9724): message : see
declaration of 'IPersist' C:\Program Files (x86)\Windows
Kits\10\Include\10.0.22000.0\um\objidl.h(11125): message : see
declaration of 'IPersistStorage' C:\Program Files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\atlmfc\include\afxwinforms.inl(32):
message : This diagnostic occurred while importing type
'System::Windows::Forms::Control ' from assembly
'System.Windows.Forms, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'. C:\Program Files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\atlmfc\include\afxwinforms.inl(32,3):
warning C4691: 'IQuickActivate': type referenced was expected in
unreferenced module 'System.Windows.Forms.Primitives', type defined in
current translation unit used instead C:\Program Files\Microsoft
Visual
Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\atlmfc\include\afxwinforms.inl(32,3):
message : This diagnostic occurred while importing type
'System::Windows::Forms::Control ' from assembly
'System.Windows.Forms, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'. C:\Program Files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\atlmfc\include\afxwinforms.inl(32,3):
warning C4691: 'IOleInPlaceUIWindow': type referenced was expected in
unreferenced module 'System.Windows.Forms.Primitives', type defined in
current translation unit used instead C:\Program Files\Microsoft
Visual
Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\atlmfc\include\afxwinforms.inl(32,3):
message : This diagnostic occurred while importing type
'System::Windows::Forms::Control ' from assembly
'System.Windows.Forms, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
before giving this error:
C:\Program Files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.30.30705\atlmfc\include\afxwinforms.inl(32,3):
fatal error C1001: Internal compiler error. (compiler file
'd:\a01_work\20\s\src\vctools\Compiler\CxxFE\sl\p1\c\cpimport.cpp',
line 12502) To work around this problem, try simplifying or changing
the program near the locations listed above.
So, my main questions are:
Is it possible to do this, can I embed a WinForms control in an MFC dialog using a CWinFormsControl in .NET6.0?
If it is possible, where am I going wrong causing the problems above?
If it isn't possible, is there an alternative way to do something like this: (trimmed down sample)
//C#
public class MyUserControl : System.Windows.Forms.UserControl
{
}
//C++
#include <afxwinforms.h>
class MyWnd : public CWnd
{
public:
CWinFormsControl<MyUserControl> mMyControl;
int OnCreate(LPCREATESTRUCT lpCreateStruct)
{
auto rc = __super::OnCreate(lpCreateStruct);
if (rc >= 0)
{
CRect rcChild(0, 0, lpCreateStruct->cx, lpCreateStruct->cy);
m_optionsControl.CreateManagedControl(WS_CHILD | WS_VISIBLE, rcChild, this, 1);
}
return rc;
}
};
I can reproduce this in a quick, small sample.
In Visual Studio 2022 create a new project, CLR Empty Project (.NET)
Add a header and source file, include the header from the source. #include <afxwinforms.h> to the header file.
Project->Properties->Configuration Properties->Advanced:
Use of MFC: Use MFC in a shared DLL
Common Language Runtime Support: (should already be) .NET Core Runtime Support (/clr:netcore)
.NET Core Target Framework: (should already be) net6.0
Build the project, you should get an error about not being able to find the System.Windows.Forms.dll.
Project->properties->Configuration Properties -> C/C++ -> General: Additional #using Directories:
C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App\6.0.0\ OR
C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.0\ref\net6.0\ OR
C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\6.0.0<br />
Build again, you should get the internal compiler error.
i was trying to solve the same issue. From the code inside mfc its clear they only support .net framework for now.
What worked for me was to make a copy of the afxwinforms.h and .inl plus some files from "C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.32.31114\atlmfc\src\mfcm" into my project directly so it stops linking into the microsoft mfcmXXX.lib and just adjusted the files slightly to get it to compile.
Here is how I fix it:
Use Visual Studio 2022, in project.vcxproj, add this reference:
<ItemGroup><FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" /></ItemGroup>
Then, you will see "System.Windows.Forms.dll" in "External Dependencies" of Solution Explorer. Look at the properties for this dll, which is under: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.7\ref\net6.0\System.Windows.dll
open project's property, Configuration Properties -> C/C++ -> General -> Additional #Using Directories, add the folder's full path there.enter image description here
(I just use net6.0, not net6.0-window)
I wrote a c# console application that I want to compile for a linux machine. When I use the following command in the console, I get this error:
dotnet publish -r linux-x64 --self-contained true
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(3983,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveManifestFiles" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [X:\Coding\Visual Studio 2019\Projects\firstDiscordBot\firstDiscordBot\firstDiscordBot.csproj]
I read through a lot of similar questions but none of the solutions worked for me. I tried deleting the .vs folder inside my solution's project folder and did Clean and Build and I tried entering Install-Package MSBuildTasks into the NuGet Package Manager Console and then rebuilding my project.
(Error message in plain text, maybe a bit easier to read:)
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(3983,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveManifestFiles" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [X:\Coding\Visual Studio 2019\Projects\firstDiscordBot\firstDiscordBot\firstDiscordBot.csproj]
[Edit]
I did some experiments and now the error message says the following:
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(3975,5): error MSB4062: The "Microsoft.Build.Tasks.SignFile" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [X:\Coding\Visual Studio 2019\Projects\firstDiscordBot\firstDiscordBot\firstDiscordBot.csproj]
I guess the error is basically the same, it probably won't matter much.
I also did some more research and I tried several more things, such as using the 'Publish' feature when right-clicking my project in the Solution-Explorer and reinstalling the SDK. I also verified all my files several times but none of the above helped.
I just want to mention that every little suggestion would be greatly appreciated as this is the first time, that I don't seem to able to fix the problem, even after multiple hours of research and dedication. So if there's anything you think I could do, I would be very happy.
For anyone with the same issue, I fixed it. My problem was simply that I was using a .NET-Framework project instead of .NET-Core. Watch out on that.
I have AspNet.MVC application and want to build MVC views during the build (only in Release configuration).
I create this target
<Target Name="BuildViews" Condition="'$(configuration)'=='Release'" AfterTargets="Build">
<AspNetCompiler VirtualPath="/" PhysicalPath="$(ProjectDir)" />
</Target>
In Debug configuration it builds
In Release it fails with error
error MSB4062: The "Microsoft.Build.Tasks.AspNetCompiler" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Installing Microsoft.Build.Tasks.Core, adding UsingTask and other manipulations doesnt help(
Maybe anyone knows the solution?
Target framework - new 4.8
C# version - 8
IDE - JetBrains Rider 2019.3.1
MSBuild Path - C:\Program Files\dotnet\sdk\3.1.101\MSBuild.dll
Project format - Microsoft.NET.Sdk (.net core format)
Also, i try to change MSBuild Path (in rider settings)
If i change it to exe-file in rider folder C:\Program Files\JetBrains\JetBrains Rider 2019.3.1\tools\MSBuild\Current\Bin\MSBuild.exe, it works
But this is not a solution, because it doesnt work on TeamCity agents, where rider is not installed
Just had the same issue with the BuildTools in Team City... Depending on what build tools you need there are different paths to it as some exist in \Microsoft Visual Studio\2019\Professional\MSBuild\ and some are in MSBuild\2019\<path>. For me this issue was resolved by updating my .config towards VS and not the build tools.
I am trying to perform a build on a WPF (.Net Core 3.1) in Visual Studio Code (not Visual Studio this time cause I need a more lightweight editor).Normally all my project can be built fine, but this WPF project gave me this following error:
C:\Program Files (x86)\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.
WinFX.targets(225,9): error MSB4062: The "Microsoft.Build.Tasks.Windows.MarkupCompilePass1" task could not be loaded from
the assembly C:\Program Files %28x86%29\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\tools\netcoreapp2.1\PresentationBuildTasks.dll. Could not load file or assembly 'C:\Program Files
%28x86%29\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\tools\netcoreapp2.1\PresentationBuildTasks.dll'. The system cannot find the path specified.
Confirm that the <UsingTask> declaration is correct, that the assembly and all
its dependencies are available, and that the task contains a public class that
implements Microsoft.Build.Framework.ITask. [E:\ui_wpf_test\ui_wpf_test.csproj]
The build failed. Fix the build errors and run again.
I heard that it has to do with MSbuild, but I dont know how to correctly fix this
I found a solution on GitHub. You have to replace the following line of %ProgramFiles(x86)%\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFx.props:
<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll'))</_PresentationBuildTasksAssembly>
Replace it with:
<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll</_PresentationBuildTasksAssembly>
This has eventually worked for me.
small bug. should be fixed in the new upcoming 3.1.103 instead of now 3.1.102.
Problem is the path Program Files (x86)' where(x86)is escaped to%28x86%29`, resulting in path not found.
temporary fix by just escaping the path:
Go to:
C:\Program Files (x86)\dotnet\sdk\3.1.102\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets
edit Microsoft.WinFx.props and use this _PresentationBuildTaskAssembly which has the Unescape for the path:
<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$([MSBuild]::Unescape($([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll'))))</_PresentationBuildTasksAssembly>
It is possible that you can resolve it also by changing in visual studio the build to x64 instead of Any CPU/x86. With 64-bit this will use C:\Program Files\ instead of C:\Program Files (x86)\ and thus not have the 'bad' characters.
I have a visual studio solution with about 8 projects. 6 csproj and 2 vsxproj.
I had to migrate the proj files from VS 2010 to VS2017. So i started using the latest msbuild version for vs2017.
Faced a new post build error after this, that first says,
Done executing task "CL".
Task "CL"
Read Tracking Logs:
T:\components\collectors\buildoutput\x64\Release\tmp\hp-scom-.10EE536C.tlog\CL.read.1.tlog
Outputs for C:\USERS\_SDSBUILD\APPDATA\LOCAL\TEMP\.NETFRAMEWORK,VERSION=V4.0.ASSEMBLYATTRIBUTES.CPP:
T:\COMPONENTS\COLLECTORS\BUILDOUTPUT\X64\RELEASE\TMP\.NETFRAMEWORK,VERSION=V4.0.ASSEMBLYATTRIBUTES.OBJ
C:\Users\_sdsbuild\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cpp will be compiled because it was not found in the tracking log.
Outputs for C:\USERS\_SDSBUILD\APPDATA\LOCAL\TEMP\.NETFRAMEWORK,VERSION=V4.0.ASSEMBLYATTRIBUTES.CPP:
T:\COMPONENTS\COLLECTORS\BUILDOUTPUT\X64\RELEASE\TMP\.NETFRAMEWORK,VERSION=V4.0.ASSEMBLYATTRIBUTES.OBJ
Write Tracking Logs:
T:\components\collectors\buildoutput\x64\Release\tmp\hp-scom-.10EE536C.tlog\CL.write.1.tlog
After this, there is another error.
Using "MIBPostProcessDependencyGraph" task from assembly "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\Microsoft.Build.CppTasks.Common.dll".
Task "MIBPostProcessDependencyGraph"
To improve incremental build performance for managed components, please make sure that the 'VC++ Directories->Reference Directories' points to all the paths which contain the referenced managed assemblies.
Could not load file or assembly 'general.Interop, Version=1.30.21.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
To improve incremental build performance for managed components, please make sure that the 'VC++ Directories->Reference Directories' points to all the paths which contain the referenced managed assemblies.
Could not load file or assembly 'Google.ProtocolBuffersLite.Serialization, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589' or one of its dependencies. The system cannot find the file specified.
To improve incremental build performance for managed components, please make sure that the 'VC++ Directories->Reference Directories' points to all the paths which contain the referenced managed assemblies.
Could not load file or assembly 'Collector2007, Version=3.10.18.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Done executing task "MIBPostProcessDependencyGraph".
Done building target "ManagedIncrementalBuildPostProcessDependencyGraph" in project
Not much information in the internet for this post build task MIBPostProcessDependencyGraph.
Could anyone please shed some light on this task and try to make me understand what this error is all about ?
Note: the compilation is done and the libraries are generated but this post build task failure causes some errors. SO wanted to understand and solve this.
Is ManagedIncrementalBuildPostProcessDependencyGraph not able to get the referenced libs while the compilation and pre compilation tasks were able to get those ?
Thanks in advance.
MIBPostProcessDependencyGraph post build task fails in msbuild
When you open the file Microsoft.Metagen.targets under the folder C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140:
<Target Name="ManagedIncrementalBuildPostProcessDependencyGraph"
Condition="'#(ClCompile)' != '' and '$(EnableManagedIncrementalBuild)' == 'True'"
DependsOnTargets="GetReferenceAssemblyPaths"
AfterTargets="$(ManagedIncrementalBuildProcessDependencyGraphAfterTarget)"
>
<PropertyGroup>
<MIBProcessDependencyGraphExcludedFolders Condition="'$(MIBProcessDependencyGraphExcludedFolders)' == ''">$(ExcludePath);$(FrameworkDir);$(VSInstallDir);$(_FullFrameworkReferenceAssemblyPaths)</MIBProcessDependencyGraphExcludedFolders>
<MIBSearchPaths>$(ReferencePath);#(ClCompile->'%(AdditionalUsingDirectories)'->Distinct())</MIBSearchPaths>
</PropertyGroup>
<MIBPostProcessDependencyGraph
Sources ="#(ClCompile)"
SearchPath ="$(MIBSearchPaths)"
ExcludedInputPaths ="$(MIBProcessDependencyGraphExcludedFolders)"
IntDir ="$([System.IO.Path]::GetFullPath($(TLogLocation)))"
ContinueOnError ="true"
TLogReadFiles ="#(CLTLogReadFiles)"
TLogWriteFiles ="#(CLTLogWriteFiles)"
/>
</Target>
It used to add the manage dll path to the MIB searching path. To resolve this issue, you can try to do as the the error messages said:
To improve incremental build performance for managed components,
please make sure that the 'VC++ Directories->Reference Directories'
points to all the paths which contain the referenced managed
assemblies.
You can check this thread for some details.
Hope this helps.