Maui App not working with Android Simulator namespace missing - visual-studio-2022

I installed Visual Studio 2022 Preview Getting error when running Maui App using Android or Machine Simulator. Is anyone having the same issue?
Already installed
Single-project MSIX Packaging
Android device Manger
Namespace missing if add the namespace still not working
error "Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'MauiApp' could not be found (are you missing a using directive or an assembly reference?) MauiApp37 (net6.0-android)"
Missing namespace if I include it still not working "using Microsoft.Maui.Hosting;"
Second Error
Severity Code Description Project File Line Suppression State
Error NU1605 Detected package downgrade: Microsoft.WindowsAppSDK from 1.0.0-preview3 to 1.0.0-experimental1. Reference the package directly from the project to select a different version.
MauiApp37 -> Microsoft.AspNetCore.Components.WebView.Maui 6.0.101-preview.10.2068 -> Microsoft.WindowsAppSDK (>= 1.0.0-preview3)
MauiApp37 -> Microsoft.WindowsAppSDK (>= 1.0.0-experimental1) MauiApp37

Your main class is MainApplication of type MauiApplication
That means that the template that you used to create that project is old (I think it was preview 6 or 7)
If you create a new .NET MAUI App with a newer template, you will see that the main class is something like this. And it's the only main file
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
return builder.Build();
}
}
So I would recommend creating a new project using a new template, and then migrate the rest of the classes/views (use the same name for your project to make it easier)

Related

R file not generated for androidTests when using AGP 4.2.0 or 7.0

I have tried migrating to a new Gradle Plugin, but since we have some custom layouts for AndroidTests, it fails with an error saying "R class was not found" for the android tests.
I could not find any source saying about any behaviour changes in this area.
The error looks like this and seems to be related to view inding or simply to the fact the R class is not generated.
/pathToTheApp/build/generated/data_binding_base_class_source_out/debugAndroidTest/out/com/package1/test/databinding/CustomViewActivityBinding.java:12: error: cannot find symbol
import package.name.test.R;
^
symbol: class R
location: package package.name.test
I had this problem in our Android tests after upgrading to AGP 7.0. Our test R class could not be found. I managed to fix it by duplicating the testApplicationId into the seemingly new testNamespace field.
android {
testNamespace = "com.example.tests"
defaultConfig {
testApplicationId "com.example.tests"
}
}
I think it should work without it, so maybe this is a plugin bug, but the docs say:
The namespace used by the android test and unit test components for the generated R and BuildConfig classes

Can not compile xUnit test classes (via mono) to exe file, using mcs command

I am using MSYS2 and mono in order to run C# project (in .NET Framework) in Linux environment on Windows machine.
My projects are placed in the path: D:\MyRootPath and there I have two separate solutions:
D:\MyRootPath\MainProject - this is my main project;
D:\MyRootPath\xUnitProject- this is a separate solution that contains project that I use for unit testing with xUnit.net framework (for .NET Framework);
Building main project (working sample)
Inside of D:\MyRootPath\MainProject I have a sample class D:\MyRootPath\MainProject\HelloWorld.cs:
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello Mono World");
}
}
When I want to build this via mono, to create an .exe file and run it, I am using the following commands inside of the MSYS2 console (this approach is working well):
mcs /d/MyRootPath/MainProject/HelloWorld.cs
mono /d/MyRootPath/MainProject/HelloWorld.exe
Building xunit project (need help here)
Inside of the xUnitProject, I have many classes, where each class represent a test case (and each test case have reference to the main project - MainProject.dll). One example of test case is D:\MyRootPath\xUnitProject\SampleRectangle.cs:
using MainProject;
using System;
using Xunit;
namespace xUnitProject
{
public class SimpleRectangle
{
[Fact]
public void simpleRectangle()
{
//this content is irrelevant to the question, I have a few Assert checks
Assert.Equal("someVariable", someVariable);
Assert.Equal("someOtherVarialble", someOtherVarialble);
}
}
}
Here I need to build this via mono, to create an .exe file and run it. Since I have many classes like SimpleRectangle, I need to run them all and to have separate .exe files for each.
So I am trying to build the test classes with the following (similar as above working example):
mcs /d/MyRootPath/xUnitProject/SampleRectangle.cs -r:/d/MyRootPath/xUnitProject/bin/Debug/MainProject.dll:/d/MyRootPath/xUnitProject/bin/Debug/xunit.core.dll
where I had to add -r flag, since it points to the .dll files that are used.
The output that I got is:
D:/MyRootPath/xUnitProject/SimpleRectangle.cs: error CS0012: The type `System.Attribute' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
D:\MyRootPath\xUnitProject\bin\Debug\xunit.core.dll (Location of the symbol related to previous error)
D:/MyRootPath/xUnitProject/SimpleRectangle.cs: error CS0103: The name `Assert' does not exist in the current context
D:/MyRootPath/xUnitProject/SimpleRectangle.cs: error CS0103: The name `Assert' does not exist in the current context
error CS5001: Program `SimpleRectangle.exe' does not contain a static `Main' method suitable for an entry point
Compilation failed: 4 error(s), 0 warnings

MSBuild 15: The "Error" task could not be instantiated

I'm attempting to programmatically build a project which uses C#7, and therefore MSBuild 15, but this task is failing seemingly because of mismatched assembly references.
Here is my code:
string projectFilePath = Path.Combine(args.Any() ? args.First() :#"C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln");
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("Configuration", "Debug");
globalProperty.Add("Platform", "x86");
BuildParameters bp = new BuildParameters(pc);
bp.Loggers = new ILogger[] { new Logger(), new ConsoleLogger(), };
BuildRequestData BuidlRequest = new BuildRequestData(projectFilePath, globalProperty, "4.0", new string[] { "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, BuidlRequest);
Here is the error message:
C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln.metaproj : error MSB4127: The "Error" task could not be instantiated from the assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.Error' to type 'Microsoft.Build.Framework.ITask'.
C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln.metaproj : error MSB4060: The "Error" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
Here is a link to a project you can use to recreate the issue:
https://drive.google.com/a/xibis.com/file/d/0B-mqMIMqm_XHcVRJQmtxQkd1b3c/view?usp=sharing
You will have to change the path in the code to a project on your own machine, but it doesn't seem to matter if this is a VS 2017 project or earlier.
One other thing that may or may not be relevant, I noticed that the Microsoft.WebApplication.Build.Tasks.Dll in this folder:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications
Still seems to be referencing Microsoft.Build.Framework.dll version 14, not 15 as I would have expected.
It turns out there are two issues in my test project. The first is due to the naming of the project.
However there is a second issue which is due to the references not being correct. To use MSBuild 15 programmtically you must install the following packages:
Install-Package Microsoft.Build -Version 15.1.1012
Install-Package Microsoft.Build.Framework -Version 15.1.1012
Install-Package Microsoft.Build.Tasks.Core -Version 15.1.1012
Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012
Install-Package Microsoft.Net.Compilers -Version 2.2.0
There is one more step which is nuts and completely undiscoverable. You must now add a reference to this DLL which should be relative to your solution folder:
packages\Microsoft.Net.Compilers.2.2.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll
I opened a support ticket with Microsoft and they have confirmed that this is a bug in Visual Studio 2017.
They are aiming to get a fix for this into update 3 for Visual Studio, but this may slip.
This issue tracks the bug:
https://github.com/Microsoft/msbuild/issues/2194
There is no workaround at present for this API, but you can invoke the MSBuild exe using Process as an alternative.
If you have MSBuild installed on your PC, either directly or through Visual Studio, the proper fix is to use the package Microsoft.Build.Locator which will find that installed version and execute the build using it.
Install these packages
Microsoft.Build
Microsoft.Build.Framework
Microsoft.Build.Locator
The first 2 are needed so that the code can compile but should be excluded from the project output.
In your application startup add the following line of code, this only has to run once.
Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
Remove any additional binding redirects in your app.config that are specific to Microsoft.Build or other build libraries. The call to the Microsoft.Build.Locator assembly will ensure that these redirects take place automatically.
References
Update an existing application for MSBuild 15
Github MSBuildLocator.

Error while running a simple GWTP Project in eclipse

`I'm new to gwtp and trying to learn it .I am trying to run a simple gwtp project on eclipse (Kepler) and my gwtp project contains a new presenter I have created under client package and i have only edited the UI.xml file just to check .But I dont seem to understand what the problem is ,as I'm trying to run the project in super dev mode Click here to see the console snap, i am getting this error :
Starting Jetty on port 8888
[WARN] FAILED guiceFilter: com.google.inject.ConfigurationException: Guice configuration errors:
1) No implementation for com.gwtplatform.dispatch.rpc.server.Dispatch was bound.
while locating com.gwtplatform.dispatch.rpc.server.Dispatch
for parameter 1 at com.gwtplatform.dispatch.rpc.server.guice.DispatchServiceImpl.(DispatchServiceImpl.java:54)
while locating com.gwtplatform.dispatch.rpc.server.guice.DispatchServiceImpl
2) No implementation for com.gwtplatform.dispatch.rpc.server.RequestProvider was bound.
while locating com.gwtplatform.dispatch.rpc.server.RequestProvider
for parameter 2 at com.gwtplatform.dispatch.rpc.server.guice.DispatchServiceImpl.(DispatchServiceImpl.java:54)
while locating com.gwtplatform.dispatch.rpc.server.guice.DispatchServiceImpl
You are most probably missing the installation of the GWTP needed modules.
Client Module file you need to install the GWTP modules (DefaultModule and RpcDispatchAsyncModule).
You should have something like:
public class ClientModule extends AbstractPresenterModule {
#Override
protected void configure() {
install(new DefaultModule());
install(new RpcDispatchAsyncModule()); // binds DispatchAsync to RpcDispatchAsync
install(new ApplicationModule()); //This is your main application module
// DefaultPlaceManager Places
bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.home);
bindConstant().annotatedWith(ErrorPlace.class).to(NameTokens.home);
bindConstant().annotatedWith(UnauthorizedPlace.class).to(NameTokens.home);
}
}

Visual Studio 2012 Hot towel template not working correctly

I am following this tutorial for getting started with Hot towel, I have installed the ASP.NET Web Tools 2012.2 update and have also downloaded and installed the VSIX for the Hot towel template, but when I try create a new project with this template it is not working correctly. If I open a new project in Visual Studio 2012 and select ASP.NET MVC 4 Web Application I see the HotTowel Single Page Application template listed there, but I select the project gets created with a lot of files missing.
What I would expect to see in my Scripts folder is the following:
But instead my project looks like this:
The project created also does not compile, it throws the following exception:
Error 1 The name 'BundleConfig' does not exist in the current context
This exception is being thrown here:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
Does anyone know why the Hot towel template is not working correctly in Visual Studio 2012 and what I could do to get it working?
UPDATE:
I tried installing Hot Towel with Nuget instead of the template, but that also did not work correctly. Install-Package got as far as installing Q and then gave an exception. Here is the Nuget output:
PM> Install-Package HotTowel
Attempting to resolve dependency 'Breeze.WebApi (≥ 1.4.1)'.
Attempting to resolve dependency 'Breeze.Client (≥ 1.4.2)'.
Attempting to resolve dependency 'Q'.
Install-Package : External packages cannot depend on packages that target projects.
At line:1 char:1
+ Install-Package HotTowel
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
I solved this problem by updating NuGet Package Manager. I updated it from here:
http://docs.nuget.org/docs/start-here/installing-nuget