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.
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'm trying to follow the instructions at https://developers.google.com/optimization/introduction/installing.html#windows_binary so that I can use or-tools inside my C# application.
I'm stuck on the make all step. I am in the Developer Command Prompt, but this command says:
'make' is not recognized as an internal or external command,
operable program or batch file.
I tried downloading GNU make, but that fails also. make install says "no target", and a bare make says:
process_begin: CreateProcess(NULL, cl /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo /O2 -DNDEBUG -DUSE_CBC -DUSE_CLP /D__WIN32__ /Iinclude\src\windows /DGFLAGS_DLL_DECL= /DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /Iinclude /Iexamples -DUSE_GLOP -DUSE_BOP -c examples\cpp\costas_array.cc /Foobjs\costas_array.obj, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [objs\\costas_array.obj] Error 2
I also tried copying the DLLs from the bin folder directly into my project. I was able to compile against them by doing this, but when I tried to run it I got an error:
System.BadImageFormatException: 'Could not load file or assembly 'Google.OrTools, Version=5.1.6235.37215, Culture=neutral, PublicKeyToken=7a052e3db761d3be' or one of its dependencies. An attempt was made to load a program with an incorrect format.'
What am I missing?
Regarding the System.BadImageFormatException:
The OrTools binary format is provided in a 64bit dll.
Make sure, that your project is set to 64bit:
In Visual Studio you can check it out by right clicking on the Project --> Properties --> Build, Platform Target: This should be set to x64.
In case you have the same issue with web application, just enable 64 bits on IIS Express using Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64-bit version on IIS Express for web sites and projects
I was having this issue when using OR-Tools in a Web Application (it worked fine in a console application). I was getting:
System.BadImageFormatException HResult=0x8007000B Message=Could not load file or assembly 'Google.OrTools' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Using x64 didn't help, and Octopus was not building the project correctly either. The solution that worked for me was specifying which ASPNETCOMPILER to use (x64) in the project's .csproj :
<Project .... >
<PropertyGroup>
<AspNetToolPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>
</PropertyGroup>
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
Hi I'm running a Xamarin PCL project thats deploying to all platforms including UWP windows 10 and windows 8.
I've just merged a branch on git and resolved some conflicts (not very well clearly) and i'm getting a few errors.
The first error:
The "GenerateResourceDesigner" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'Vigour, Version=, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Vigour.dll'
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(String fullName, ReaderParameters parameters)
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(String fullName)
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.GetAssembly(String fileName)
at Xamarin.Android.Tasks.GenerateResourceDesigner.<Execute>c__AnonStorey0.<>m__0(String ass)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at Xamarin.Android.Tasks.ResourceDesignerImportGenerator.CreateImportMethods(IEnumerable`1 libraries)
at Xamarin.Android.Tasks.GenerateResourceDesigner.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Vigour.Droid
The second one:
I know this is a common problem and I've tried to un-tick and tick the build of each project in the solutions configuration.
I've also tried to remove the .vs/../.suo file to reset the project
However I've had no luck. I think that it might have something to do with the merger that involved changing the .csproj files.
Try to set API to 23 and then Rebuild the project it will solve the problem
Solution to this was to reinstall the xamarin forms for android and as #hvaughan3 said, deleting the bin and obj folder for all directories along with the packages.
In my case, I was getting error The "ResolveLibraryProjectImports" task failed unexpectedly. when I open a project downloaded from Xamarin.University on Windows 10 and the path for one of the files ends up being to long (longer than 260 characters). So, to solve my problem, I would copy the directory as shallow as possible, so instead working directly in the structure of downloaded project, I would copy deepest directory containing the project into my C:. Building would work then without an issue as the path to all files in the project got shortened.
So, say my downloaded structure from Xamarin.University is something like
C:\Users\me\Desktop\XAMARIN\XAMARIN CERTIFICATION\forms\xam300-advanced-cross-platform-development\Lab Materials\Part 03 Resources\Completed
I would copy the Completed folder into C and end up with much shorter path like:
C:\Completed
I've downloaded the IKVM sources (http://www.ikvm.net/) from http://sourceforge.net/cvs/?group_id=69637
Now I'm trying to get it to build in Visual Studio 2008 and am stuck. Does anyone know of documentation of how to build the thing, or could even give me pointers?
I've tried opening the ikvm8.sln, which opens all the projects, but trying to build the solution leads to a bunch of "type or namespace could not be found" errors.
As you can probably guess I'm no Visual Studio expert, but rather am used to working with Java in Eclipse.
So again, I'm looking for either: step-by-step instructions or a link to documentation on how to build IKVM in Visual Studio.
Let me know if you need any more info. Thanks for any help!
Edit: I've also tried a manual "MsBuild.exe IKVM8.sln", but also get a bunch of:
JniInterface.cs(30,12): error CS0234: The type or namespace name 'Internal' does not exist in the namespace 'IKVM' (a
re you missing an assembly reference?)
JniInterface.cs(175,38): error CS0246: The type or namespace name 'ClassLoaderWrapper' could not be found (are you mi
ssing a using directive or an assembly reference?)
JniInterface.cs(175,13): error CS0246: The type or namespace name 'ClassLoaderWrapper' could not be found (are you mi
ssing a using directive or an assembly reference?)
Edit #2: I noticed a "ikvm.build" file so I downloaded and ran nant on the folder, which got me a step further. A few things start to build successfully, unfortunately I now get the following error:
ikvm-native-win32:
[mkdir] Creating directory 'C:\Documents and Settings\...\My Documents\ikvm\ikvm\native\Release'.
[cl] Compiling 2 files to 'C:\Documents and Settings\...\My Documents\ikvm\ikvm\native\Release'.
BUILD FAILED
C:\Documents and Settings\...\My Documents\ikvm\ikvm\native\native.build(17,10):
'cl' failed to start.
The system cannot find the file specified
Total time: 0.2 seconds.
Edit #3: OK solved that by putting cl.exe in the path, still getting other errors though. Note this is all for building it on the console e.g. with Nant. Is there no way to get it to build in Visual Studio? That would be sad...
Edit #4: Next step was installing GNU classpath 0.95, and now it looks like I need a specific OpenJDK installation... Linux AMD64?!
[exec] javac: file not found: ..\..\openjdk6-b12\control\build\linux-amd64\gensrc\com\sun\accessibility\internal\resources\accessibility.java
[exec] Usage: javac <options> <source files>
[exec] use -help for a list of possible options
Edit #5: Got an answer from the author. See below or at http://weblog.ikvm.net/CommentView.aspx?guid=7e91b51d-6f84-4485-b61f-ea9e068a5fcf Let's see if it works...
Edit #6 As I feared, next problem: "cannot open windows.h", see separate question here.
Final Edit: Found Solution! After getting the Platform SDK folders in the Lib and Path environment variables, the solution I described below worked for me.
I don't know that this would do it for you but can you try building from the command line?
msbuild ________
I think that's how I built the application due to the same issues.
OK just got the following reply from the author: http://weblog.ikvm.net/CommentView.aspx?guid=7e91b51d-6f84-4485-b61f-ea9e068a5fcf
If you want to build from cvs, you're on your own. However, you can more easily build from source if you use an official release.
If you download ikvm-0.36.0.11.zip, classpath-0.95-stripped.zip and openjdk-b13-stripped.zip from SourceForge (the last two are under the ikvm 0.36.0.5 release) you have all the sources that are needed.
Now you'll have to open a Visual Studio 2008 Command Prompt (i.e. one that has cl.exe and peverify in the path).
Then in the ikvm root directory, do a "nant clean" followed by "nant". That should build the whole project. After you done that, you should be able to build in Visual Studio (debug target only), but you may need to repair the assembly references in the projects (unless you have ikvm installed in c:\ikvm).
Regards,
Jeroen
Edit: After making sure the Platform SDK folders were in the Path and Lib environment variables, this worked for me. Thanks, Jeroen!
This is how I built IKVM 8.1.5717.0 from source. Visual Studio is not required.
Create a folder:
c:\ikvm\
Add the above folder to PATH (e.g. set PATH=%PATH%;c:\ikvm and leave command prompt open for later).
Download:
ikvmsrc-8.1.5717.0.zip (http://www.frijters.net/ikvmsrc-8.1.5717.0.zip)
Unzip and place "ikvm-8.1.5717.0" folder in c:\ikvm\
Download:
openjdk-8u45-b14-stripped.zip (http://www.frijters.net/openjdk-8u45-b14-stripped.zip)
Unzip and place "openjdk-8u45-b14" folder in c:\ikvm\
Download:
Java 8 SDK (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
Install and make sure location is added to path
Download:
NAnt 0.92 (https://sourceforge.net/projects/nant/files/nant/0.92/nant-0.92-bin.zip/download)
Unzip and place "nant-0.92" folder in c:\ikvm\
ICSharpCode.SharpZipLib.dll (http://www.icsharpcode.net/opensource/sharpziplib/Download.aspx)
Place "ICSharpCode.SharpZipLib.dll" in C:\ikvm\ikvm-8.1.5717.0\bin\
Open the following file in a text editor and change the version number:
C:\ikvm\ikvm-8.1.5717.0\CommonAssemblyInfo.cs.in
Using command prompt from earlier, cd to:
C:\ikvm\ikvm-8.1.5717.0\ikvm\
Run:
..\nant-0.92\bin\NAnt.exe
If successful all the binaries will be in:
C:\ikvm\ikvm-8.1.5717.0\bin