Visual Studio Build Fails due to Error: MSB4025 - c#

Hi I am trying to run dotnet build <Sln file> to build the project but I am getting this error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
Build Failed
Folder Structure: C:\Users\USERNAME\PROJECTNAME\Folder0\File0.vdproj(1,1)
Dotnet Version: 6.0.301

I think that this information is useful.
vdproj is a MSI creation project for Visual Studio. Its been deprecated and most people have moved on to either WIX or NSIS or a professional grade installer creation tools such as Install Shield. If you do not require an installer for your product just exclude the vdproj project from the solution and continue with your life. For fun if you want to try to transition right away to wix, try this powershell script https://github.com/chrisoldwood/vdproj2wix
Visual Studio - vdproj is incompatible
MSI setup (.vdproj) This project can't be opened in Visual Studio 2013 because it doesn't support that project type. We recommend that you use InstallShield Limited Edition for Visual Studio (ISLE), a free deployment solution that directly supports most Windows platforms and application runtimes. You can also use ISLE to import data and settings from Visual Studio Installer projects.
Port, migrate, and upgrade Visual Studio projects

Related

Building UWP project in GitHub Action with Visual Studio 2022

I'm trying to build a UWP project as part of a Github Actions Workflow.
In my YAML I am building and running a separate project so that I can debug my CICD pipeline locally. This separate project uses msbuild to build my main UWP project. Prior to recent changes (Github upgrading to Windows Server 2022 as the default runner + my team starting to use language features which require VS2022) this worked fine. Now I'm struggling to get things to build.
I've specified in my YAML to use Windows Server 2019 and Visual Studio 2022.
The msbuild command I run consists of:
var command = #"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe";
var x86Arguments = $#"ApplicationName /restore /p:Configuration=Release /p:Verbosity=minimal /p:Platform=x86 /p:AppxBundle=Never /p:UapAppxPackageBuildMode=StoreUpload";
The error I'm hitting is:
error MSB4019: The imported project
"C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\sdk\6.0.201\Microsoft\WindowsXaml\v17.0\Microsoft.Windows.UI.Xaml.CSharp.targets"
was not found. Confirm that the expression in the Import declaration
"C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\sdk\6.0.201\Microsoft\WindowsXaml\v17.0\Microsoft.Windows.UI.Xaml.CSharp.targets"
is correct, and that the file exists on disk.
I've tried to locate the targets file in the github runner and the only copy of it is from the VS2019 installation.
I've tried various attempts at targeting this file, which don't work.
Has anyone managed to build UWP apps with msbuild with VS2022 in a Github Workflow?

Getting an exception error when trying to run the default Program.cs (C#) in Visual Studio 2019

I'm taking a course to learn C#. The course had me create a number of directories from the Command Line Interface (CLI). When I tested the directories I created in the CLI (on the top-level folder), by typing the command "dotnet run", it ran the default code correctly, returning "Hello World!"
I then moved on to open the top-level folder in Visual Studio 2019 so I could begin editing. The folder opened correctly and all of my directories were in the Solution Explorer. However, when I attempted to run the default code, I got the following exception.
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.
Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Does anyone have any idea what's going on? The strange thing is when I create a new C# project and attempt to run the code, it runs fine. It just seems to be this particular project that's giving me an issue. I deleted the directories and started over from scratch, following the tutorial step by step, but got the same exception.
I should also note that when I created the .NET file (i.e. "dotnet new") in the CLI, I created a Console Application. I created the top-level directory of "testproject". I created two directories inside of testproject: "src" and "test". Inside of the "src" directory, I created the directory "TestProject" and then inside of TestProject, I typed the command "dotnet new console". When I changed directory (cd) to "testproject" (top level), and typed the command "dotnet run" it returned "Hello World!" However, as mentioned, when I opened the top-level testproject folder in Visual Studio, and tried running, it went into break mode and threw that exception.
This noob appreciates the help!
Visual Studio version information (the application is up to date):
Microsoft Visual Studio Community 2019 Version 16.5.4
VisualStudio.16.Release/16.5.4+30011.22 Microsoft .NET Framework
Version 4.8.03752
Installed Version: Community
ASP.NET and Web Tools 2019 16.5.236.49856 ASP.NET and Web Tools 2019
ASP.NET Web Frameworks and Tools 2019 16.5.236.49856 For additional
information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 16.5.236.49856 Azure App Service
Tools v3.0.0
Azure Functions and Web Jobs Tools 16.5.236.49856 Azure Functions
and Web Jobs Tools
C# Tools
3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e C# components used in the IDE. Depending on your project type and
settings, a different version of the compiler may be used.
Common Azure Tools 1.10 Provides common services for use by Azure
Mobile Services and Microsoft Azure Tools.
IntelliCode Extension 1.0 IntelliCode Visual Studio Extension
Detailed Info
Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual
Studio 2019 - v2.9.30207.1
Microsoft Continuous Delivery Tools for Visual Studio 0.4
Simplifying the configuration of Azure DevOps pipelines from within
the Visual Studio IDE.
Microsoft JVM Debugger 1.0 Provides support for connecting the
Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft Library Manager 2.1.25+gdacdb9b7a1 Install client-side
libraries easily to any web project
Microsoft MI-Based Debugger 1.0 Provides support for connecting
Visual Studio to MI compatible debuggers
Microsoft Visual Studio Tools for Containers 1.1 Develop, run,
validate your ASP.NET Core applications in the target environment. F5
your application directly into a container with debugging, or CTRL +
F5 to edit & refresh your app without having to rebuild the container.
NuGet Package Manager 5.5.0 NuGet Package Manager in Visual Studio.
For more information about NuGet, visit https://docs.nuget.org/
ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual
Studio Extension Detailed Info
SQL Server Data Tools 16.0.62003.05170 Microsoft SQL Server Data
Tools
SQL Server Reporting Services 15.0.19103.0 Microsoft SQL Server
Reporting Services Designers Version 15.0.19103.0
TypeScript Tools 16.0.20225.2001 TypeScript Tools for Microsoft
Visual Studio
Visual Basic Tools
3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e Visual Basic components used in the IDE. Depending on your project type and
settings, a different version of the compiler may be used.
Visual F# Tools 10.8.0.0 for F# 4.7
16.5.0-beta.20181.6+85af456066acd4e76d2bc7821b44a325e46f2fca Microsoft Visual F# Tools 10.8.0.0 for F# 4.7
Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for
hosting Visual Studio Code debug adapters in Visual Studio
Visual Studio Container Tools Extensions (Preview) 1.0 View, manage,
and diagnose containers within Visual Studio.
Visual Studio Tools for Containers 1.0 Visual Studio Tools for
Containers
Why don't you create the project from within Visual Studio? File -> New -> Project.
Does a project file get created in the testproject/src/TestProject/ directory. It will be called TestProject.csproj. Open this in Visual Studio (File -> Open -> Project/Solution) and use this as your root directory. I wouldn't worry about trying to layout custom directories in Visual Studio for now since your a noob like you say.

How to create a setup for c# program?

I have read similar questions on SO and other forums but can't what I want. I have obfuscated my binaries using 3rd party tools, and want to use these binaries in the setup.
Visual Studio Installer lets us choose the projects we want to deploy, and creates the installer using the outputs of those projects.
WiX creates a setup using the files I want but does not have an option to install .NET framework, if it doesn't already exists.
Is there a way I can use my own assemblies in Visual Studio Installer ? Or a similar alternative ?
EDIT:
I have already packed all dependencies in the binary. I don't want the installer to find the dependencies for linking them. I just want it to install .net (if not already installed) and place the binaries in a directory.
Not exactly the answer you'd hope for, but you mentioned WIX and dependency to .net framework. For that reason people write bootstrappers (i.e. a binary compiled to native win32) using something like Autoit which makes sure of the framework. All you may have to do is read registry key of corresponding framework and if required it pull down the file and install. Then execute the msi !
You can use the good old Visual Studio Setup Project (Installer Project) template.
To do so, you need to download the Microsoft Visual Studio Installer Projects depending to your VS version from one of the following links:
Microsoft Visual Studio Installer Projects 2013
Microsoft Visual Studio Installer Projects 2015
Microsoft Visual Studio Installer Projects 2017 and 2019
Microsoft Visual Studio Installer Projects 2022
The project could be used to deploy anything, including your project or instead of adding Project Output you can simply right click on your setup project node in solution explorer and under Add menu, add File or Assembly.
Then all dependencies will be added automatically. You can also add other files and artifacts that you need to be installed on target machine.

Task could not be loaded from assembly

I have an error in one of my projects at work. The error says:
Severity Code Description Project File Line Suppression State
Error The "StyleCopTask" task could not be loaded from the assembly
C:\Projects\Project
Name\Source\\MSBuild\StyleCop\v4.7\StyleCop.dll. Could not load
file or assembly 'Microsoft.Build.Utilities.v3.5, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified. 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. DskDirectMarketing.Common
Here I can clearly see that there is problem in the relative path which VS is looking for StyleCop. Here is how it looks like:
<Import Project="$(SolutionDir)\MSBuild\StyleCop\v4.7\StyleCop.targets" />
and my SolutionDir declaration looks like this:
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
After some digging I noticed that in the error which prompts me there are 2 slashes:
C:\Projects\Project Name\Source\MSBuild\StyleCop\v4.7\StyleCop.dll
First thing I tried was to remove the dash from
<Import Project="$(SolutionDir)MSBuild\StyleCop\v4.7\StyleCop.targets" />
Id didn't worked.
After that I tried to put the absolute path but I had 2 slashes again.
How can I resolve this issue? Any help would be appreciated.
Based on #MaKCbIMKo's answer I installed .Net Framework 3.5 and this fixed my problem.
If you are using Windows 10, enable the .net framework 3.5 and if does not allow you to do so, open command prompt and run:
Dism /online /enable-feature /featurename:NetFX3 /All /Source:D:\sources\sxs /LimitAccess
If you're also using Visual Studio 2019 on Windows 10, you could try the following:
Close your Visual Studio instance.
Open Visual Studio Installer.
On the version of Visual Studio that you're currently using, click on More and select Modify.
Select the Individual components tab.
Search for .NET Framework 3.5 development tools, select it and click on Modify.
Wait for the modification to finish.
Open your project in Visual Studio, then do a Clean, followed by a Build.
In my case the paths were correct, but visual studio needed to run under elevated permissions to access the file in question.
We need to use visual studio installer to install the .netframework 3.5 , if the visual studio installer shows both options Visual Studio 2019 and Visual studio Build Tools 2017. follow below step
If you are using the Visual Studio 2019 ( mine was 16.11.3 but should work for all the versions). you will have Visual studio 2019 and Visual studio build tools 2017 .
Select the Visual Studio Build Tools 2017 => select modify => go to individual components => select .Net Framework 3.5 development tools
Then proceed with the installation.
-Ideally it should work once you re open the Visual studio , if not restart the system

How to log a project that is being deployed from Visual Studio?

I have a C# project written using Visual Studio Express 2013 for Windows Desktop. When I run the project in debug mode via Visual Studio (on Windows 8 Pro) it executes just fine, and so does copying the files out of the bin directory.
I need to deploy to a Windows 7 Embedded System with the correct version of .NET Framework. I tried:
copying the files over with the .dll and everythig from the bin folder and when starting I get no error, but doesn't start at all. I get no information at all.
tried the one click installer (choosing the option to install from dvd) and it seemed to install fine, but when I start it, I get same issue. Not starting, and no messages.
I also tried the Advanced Installer (free version) and when importing the visual studio project files it fails with the message "Failed to start Visual Studio. Error: Invalid Class String"
[UPDATE] Advanced Installer cannot import VS Express solutions because the API from VS that provides assistance on import is not available for VS Express edition. Only solutions created with paid editions of VS can be imported in Advanced Installer.
So how can I log or see what is happening to debug this?

Categories

Resources