We have a mixture of ASP.NET Core and .NET Framework ASP.NET apps. We use a mixture of msbuild and dotnet to build the apps.
I'm trying to go all in on dotnet, but the build always throws an error of:
error MSB4019: The imported project "C:\Program
Files\dotnet\sdk\3.0.100-preview5-011568\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
Right now I'm just trying with a very simple command of dotnet msbuild foo.sln. No flags or anything being used for now.
I've tried this on multiple ASP.NET (not Core) apps and they all give the same error.
For ASP.NET Web applications, you need to compile using the following code.
C:\'Program Files (x86)'\'Microsoft Visual Studio'\[year]\[edition]\MSBuild\Current\Bin\msbuild.exe [project.csproj] /p:VisualStudioVersion=[version] /p:DeployOnBuild=true /p:PublishProfile=[profileName]
You can run in cmd or PowerShell.
Replace tags according to the version of Visual Studio installed on your machine and solution version.
For Example:
C:\'Program Files (x86)'\'Microsoft Visual Studio'\2019\Community\MSBuild\Current\Bin\msbuild.exe HelloWorld.csproj /p:VisualStudioVersion=16.0 /p:DeployOnBuild=true /p:PublishProfile=Release
We've solved the Microsoft.WebApplication.targets missing reference by adding it as a NuGet dependency, however the dotnet msbuild command still can't compile all related framework and asp.net projects.
We've also stood up our build server inside a docker container on an ubuntu image, as we were hoping to improve our infra with containerization etc.
However we've hit a wall in building all possible projects using the dotnet executable, even though it has the msbuild command built in.
Anyone had any luck with this?
This answer indicates this is not possible though
https://stackoverflow.com/a/66366638/6578823
Related
I have created a asp.net mvc core app targeting the .net framework (not the multi platform core) as I want to include standard .net framework libraries and running cross platform is irrelevant to me as I will be hosting in Azure.
The solution looks like this:
I am trying to get a VSTS build working with this project (which is part of a larger solution) but when building I get the following error:
Which seems to be a common error. What should my build definition look like to build these .csproj based projects? There seems to be a lot of information but no definitive answer. Hopefully that answer can be here and people can stop looking elsewhere for information on how to get a Continuous Integration build going.
On a side note at the solution level I find no packages folder containing my nuget packages, why is this? The project definitely contains nuget packages.
Your project is using the newest MSBuild based project files for .NET Core.
The extension is still .csproj, but the XML schema is different than the ordinary .csproj used in .NET46 (and previous versions).
You need appropriate tooling to build such .csproj file, for example:
Visual Studio 2017: install it on your private build agent; VSTS hosted build agent does not have VS2017 installed yet;
.NET Core SDK 1.0.0-preview4-004233 (or more recent): this SDK contains the command line tool 'dotnet' for MSBuild .NET Core based projects.
Note in your build log that the msbuild used is the one shipped with VS2015 (version 14.0) instead, that does not support such .csproj format file.
On the other hand, if you do not need multiplatform nor any other benefit of .NET Core, why are you using it? Just created an ordinary ASP.NET 4 web project targetting .NET 4.6.
I am using an iball notebook and I don't have enough memory to install Visual Studio. I am having no problems using VS code and i am able to make and create executables of my console applications. I need to learn game development but everyone keeps saying that i need to install visual studio for it
However i did find a fourm on monogame on the topic and found that it is possible(At least on Linux) to use Monogame in VS code.
http://community.monogame.net/t/visual-studio-code-and-monogame/2371
Please Help me out.I want to know if it's really possible to compile and run a monogame app in windows.
Answer edited as Monogame released official dotnet project templates
I finally got it working.
I realized that all I needed was to create a monogame project (*.csproj) and Compile/Build it without Visual Studio. VS Code is just a feature-rich text editor and I would need other toolset for it.
MSBuild tool is used to Compile/Build monogame project and is available as a CLI. It is available without installing Visual Studio.
For C# project building, dotnet core is required. executing the script
dotnet new [Template]
creates a new Project. We need to add a template for monogame here.
As per the latest update by the Monogame Team, you can install the templates by executing
dotnet new --install "MonoGame.Templates.CSharp"
Use the script
dotnet new -h
to check out all the templates available.
Now, to generate the project, use the following
dotnet new mgwindows
On successful execution, this will generate [FolderName].csproj, Game1.cs, Program.cs and other files/folders of monogame project. Please not that this csproj is on .NET Framework (version 4.5 if I'm not wrong....) and therefore it might not work with dotnet run command. (If you're a bit stubborn, you might need to copy the Monogame installed folder(which contains, among many other files, Monogame.target file) in your dotnet installed folder.)
In other words, use msbuild to build and run the project
msbuild
If the program does not contain any compile time errors, the .exe file will be built successfully and you will get to see the the Output file path which you get to execute.
If you're working on Linux or have some other reason not to use MSBuild, you should not generate a mgwindows project. You can rather chose
dotnet new desktopgl
which works on dotnet core (i.e you can use dotnet run command to execute it).
I wrote this (Windows-only) solution in medium. It's a step-by-step of how to install and run dotnet with MonoGame in the terminal of VSCode.
You need to install:
.NET SDK 5.0
.NET Core SDK 3.1
.NET Runtime 5.0
You can run dotnet in your terminal and see if it's working.
Install MonoGame editor:
dotnet tool install --global dotnet-mgcb-editor
and
mgcb-editor --register
Install MonoGame Templates:
dotnet new --install MonoGame.Templates.CSharp
Create a new project in the chosen template:
dotnet new mgdesktopgl -o ProjectName
Enter in your project with cd ProjectName and add the MonoGame package to it:
dotnet add package MonoGame.Framework.DesktopGL --version 3.8.0.1641
And finally:
dotnet run Program.cs
There is absolutely no reason you cannot work with MonoGame from Visual Studio Code. It will not be an optimal setup since you'll lack debugging, and the setup will be difficult, but if you're okay with that then continue on.
You've already noted that you have no issues creating executable console applications. This is all you really need to be able to do. The key here is that you must build targeting .NET4+ or Mono. If you've followed tutorials that lead you to building .NET Core applications they will not work with MonoGame (at this time). If you are building .NET Core, spend some time looking into how to build Desktop CLR applications using MSBuild or Mono. If you need more information I can expand upon this. You'll also need to be sure you know how to reference other .NET assemblies from your console applications. Please do some research on how to do this before moving on.
For Windows you have the option of targeting DesktopGL (OpenGL) or WindowsDX (DirectX) versions of MonoGame. I'm partial to the DirectX versions myself. You'll need 2 things to get up and running: 1. the MonoGame assemblies, and 2. the MonoGame Pipeline Tool (this is used to compile your content into .XNB files so they may be imported into your game).
To get at MonoGame's assemblies and tools the easiest way I can think of is to install Visual Studio Community Edition and then download and install MonoGame for Visual Studio. This will bring all the tools to you. You'd then need to look at "C:\Program Files (x86)\MonoGame\v3.0\Assemblies" for the appropriate assemblies and "C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools" for the MonoGame Pipeline Tool.
If Visual Studio will not let you install because your machines doesn't meet the requirements then you are not out of luck. The assemblies can be pulled in via nuget. Download the latest nuget.exe here: https://dist.nuget.org/index.html and then run: nuget.exe install MonoGame.Framework.WindowsDX or nuget.exe install MonoGame.Framework.DesktopGL. This will create a directory containing a lib folder that contains a net40 folder which contains the .DLL files you need. For WindowsDX I think you'll also need the DirectX runtime https://www.microsoft.com/en-us/download/details.aspx?id=34429. For OpenGL I think you'll need OpenAL (for audio) https://www.openal.org/downloads/.
Once you have the assemblies you'll need to reference them when you build your code. As you've said you're already familiar with creating and running console applications I'll assume you know how to do this. Just reference every managed .DLL you downloaded with Nuget or pulled from the Assemblies folder from the install.
To test things out, drop this into a .cs file, reference the MonoGame assemblies in your build, build it as you would a console application, and execute:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
public class Game1 : Game
{
GraphicsDeviceManager graphics;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
}
[STAThread]
static void Main()
{
using (var game = new Game1())
game.Run();
}
}
You should get a window with a cornflower blue background. If you don't, then you're not building or referencing things right, or you're missing a dependency.
The trick now is getting your hands on the Pipeline Tool, and MGCB.exe. If you were able to install MonoGame for Visual Studio, great!, these files are in the folder I references above. If not, for whatever reason the MonoGame project doesn't distribute stand alone versions of these, only with the installer. I've taken the contents of what you need and plopped it into a dummy release on GitHub here: https://github.com/srakowski/derp/releases/tag/MG. Download the Pipeline.zip file, extract it, and you should have what you need.
Create an empty Content.mgcb file and open it with Pipeline.exe. You should be able to add and build content files. You'll need to copy these files into the same directory where your .exe lives. Commonly, these are put into a Content folder, and Content.RootDirectory = "Content"; is added to the Game's constructor.
Once you get all this working you should be free and clear to create games as your heart desires. Please let me know if you have troubles and we'll work things out.
I've tried Monogame on Visual Studio and own a Windows PC. So I can safely confirm that Monogame does work on Windows. To answer your question.
However, if you want to try it without Visual Studio, then I don't think you can really get far. as there are several build in tools needed to make a decent one. And you cannot debug it either. You're working really limited if you cannot use Visual Studio.
Try to clean up your PC to make some free space. Visual Studio would really be a better choice to work with.
A TFS 2012 build server with .NET 4.6 installed produces the error message below when trying to build a website targetting .NET 4.6.
The machine has been restarted since the install.
Do I need to somehow tell TFS to favor .NET 4.6?
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets
(983): The reference assemblies for framework
".NETFramework,Version=v4.6" were not found. To resolve this, install
the SDK or Targeting Pack for this framework version or retarget your
application to a version of the framework for which you have the SDK
or Targeting Pack installed. Note that assemblies will be resolved
from the Global Assembly Cache (GAC) and will be used in place of
reference assemblies. Therefore your assembly may not be correctly
targeted for the framework you intend.
I installed the .NET Framework 4.6 Targeting Pack on the build server and that resolved it for me.
Firstly, you need to be sure that all referenced assemblies in the project can be found on the TFS build server. For best practice, you need to install VS2015 on the build server machine.
Secondly, you need to customize your TFS build process template to explicitly set the ToolPath variable in the Run MSBuild for Project activity to be C:\Program Files (x86)\MSBuild\14.0\Bin. Or add /tv:14.0 argument to MSBuild command.
When using Team City for CI builds there is an option to use the Resharper command line tools to run Code Analysis inspection of the code as one of the build steps.
I have this working with reference library projects but the mvc.net project in the solution fails with reference errors:
One or more types required to compile a dynamic expression cannot be
found. Are you missing references to Microsoft.CSharp.dll and
System.Core.dll?
Even with the default Microsoft template there are over 200 errors and they seem to all come from the razor views. (The project compiles and deploys from the build server correctly and FXCop also runs successfully, this seems to be an issue just for resharper tool.)
I can run the resharper code inspection in visual studio without errors.
In Team City I just have a default Inspection (.NET) build running pointing at the .sln file.
We are using Resharper Command Line Tools 9.1.201 as provided with TeamCity 9.0.4
What configuration or additional steps can I take to get the resharper command line tool to resolve mvc view references on the build server?
If resolving the references is not possible, can the razor views be excluded from the analysis without needing to add each exclusion to the command line?
For future reference, I just had the same issue. Digging through the build log, I noticed a seemingly unrelated warning:
The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found.
I retargeted my project to .NET 4.6 and installed the .NET 4.6 targeting pack, and the code inspection errors are gone. Unfortunately, I don't know if just installing the .NET 4.5.2 targeting pack would have solved the issue.
I have recently run into an issue where (for some reason this behaviour has appeared out of nowhere) during web deployment of a project to Azure Websites - some reference assemblies of the dependent projects are not automatically included into the deployment package.
SO this is a rough structure of my project:
1) ASP.NET MVC project that references class library project
2) Class library project that references some NuGet packages
Now, when I web deploy the ASP.NET MVC project to Azure Website - not all of the NuGet packaged assemblies from the reference class library are deployed (it seems that some are included automatically and others are not). Everything works fine when run locally. All of the required assemblies are copied over to the bin folder of the ASP.NET MVC project.
Now, the only way that I have found to work around this issue is to add the NuGet package of the missing reference directly to ASP.NET MVC project. I really don't like this workaround - since it breaks the modular structure of my project.
Surely there must be a way to specify which assemblies are to be included with Web Deploy? I have tried some pretty extensive google searches on the topic - but that didn't yield an working solution.
Try the following for each of the offending Nuget packages:
Open the Package Manager Console. Make sure the Default Project dropdown is set to your MVC project.
Run Uninstall-Package [Package Name] -Force
Run Install-Package [Package Name]
If you need to keep a particular version of a package instead of just pulling the latest in, you can add -Version [Version Number] to the end of the last command.
That will essentially refresh all the references and other bootstrapping for the package, then try to web deploy again.