MSB4018: The task failed unexpectedly

jonny22

Member
Joined
May 14, 2022
Messages
23
Programming Experience
1-3
Hi, after reinstalling Visual Studio, I get the error in question by recompiling a program that I had previously written and that worked correctly.
At the same time it is also reported that the "AssemblyInfo.cs" file is not found
I tried to reset visual studio and update packages but i can't fix the problem, does anyone know how to fix it?
 
At the same time it is also reported that the "AssemblyInfo.cs" file is not found
Did you check whether the file is there or not? Is it there or not? What type of project is it exactly and what framework is it targeting? I'm guessing that it's targeting .NET Framework rather than .NET Core, as I don't think the latter uses that file. If you create a new, similar project, do you see that file included? If you do and it's missing from the other project, you could copy it across and edit it appropriately.

This is also an example of why everyone should be using source control. If strange things like this happen for whatever reason, you can always roll back to a previous good version.
 
Hello, yes net framework, a console type program, I had the backup on an external disk and I copied it to the same location on the internal disk where it was before the problem, the AssemblyInfo.cs file is present in the backup, only I need to recompile the project, when I recompile it the AssemblyInfo.cs file disappears, it is deleted.
 
Where exactly is that file located? Is it under Properties, both in the Solution Explorer and the file system? If you open the project file in a text editor, is that file referenced? I just opened a basic .NET Framework Console app project file and I saw this:
XML:
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
Do you see something similar?
 
It's a simple console app, I've also tried creating a new project, and compiling the default line of code that prints "Hello World", it gives the same error.
No, I didn't have any specific problems, just a crowded disk so I decided to format it and install only the strictly necessary applications, then I reinstalled Visual Studio and I started having the problem.
 
I've already tried to repair via the installer, and it didn't fix it, but I could uninstall and then download Visual Studio again and try installing again.
 
D:\foldername\subfoldername\subsubfoldername\obj\Debug\net6.0\name.AssemblyInfo.cs

That doesn't make any sense. You said that you're targeting .NET Framework, so why would it be under a folder for targeting .NET 6? That obj folder is for intermediate build files. It should be of no interest to you. The source files are in the project folder and the output files are in the bin folder. That's all you should care about. I would suggest that you delete the existing bin and obj folders, which you may have to close VS to do. You can then try rebuilding and see if that works but you probably need to establish what framework you're targeting and where the initial source version of the file should be, if at all.
 
I just checked a .NET 6 project and there is no source version of that file but, as you say, there is a version in the obj folder and named after the assembly. .NET Core (.NET 5 and later are based on .NET Core) must only generate that file when building, rather than using an original source. Not sure where the information actually comes from but will take a look when I can.
 
What I downloaded is the version which I believe is called Visual Studio Comunity, now I don't remember exactly, but the difference between net core and net framework is that one is newer right?
Did I then download the wrong version?
 
It appears that that generated file contains default values unless you set some in the project properties, in which case they are stored in the project file and copied across during build. You might try setting something like the Copyright or Version value in the project properties and rebuilding, to see whether that can knock some sense into VS. I can see those values stored in my project file and reflected in the file in the obj folder after a build.
 
What I downloaded is the version which I believe is called Visual Studio Comunity, now I don't remember exactly, but the difference between net core and net framework is that one is newer right?
Did I then download the wrong version?

VS 2022 allows you to target both. .NET Framework is not being developed beyond version 4.8.x. .NET Core was developed up to version 3.1 and .NET 5 was basically the merger of the two but based on .NET Core. When you create a project, if you don't select a template that specifically states that it's targeting .NET Framework, you're targeting .NET Core. They are now up to previewing .NET 8, so things roll on.
 
Back
Top Bottom