Why does Visual Studio 2019 remove for new .razor files
In Visual Studio Professional 2019 v 16.8, in my Blazor client's .csproj file, I have a line inside an ItemGroup:
<Watch Include="**\*.razor;**\appsettings.*" />
That way, whenever I change a .razor file, dotnet watch run
will rebuild and restart the web server automatically. Great.
But now, whenever I create a .razor file in the project (such as Foo.razor), Visual Studio quite unhelpfully adds a "remove" line, such as:
<Watch Remove="Components\Widgets\Foo.razor" />
It also adds this, sometimes:
<Content Remove="Components\Widgets\Foo.razor" />
I then have to manually edit the csproj file to remove these lines. Why is it doing this, and how can I turn it off? Or is there something bigger that is wrong here? Some searching found no one else dealing with this; maybe I have something wrong with my setup?
(I saw exactly the same behavior in earlier versions.) Thanks in advance.
1 answer
-
answered 2020-11-25 07:32
Rogier
I have reported this issue and should be resolved at some point: https://github.com/dotnet/aspnetcore/issues/27718
See also questions close to this topic
-
Dapper - creating objects with queries on database with one-to-many and many-to-many relationships
I have an Sqlite database, for a which a partial schema is:
In the code, classes representing the data are as follows (simplified):
public Book : Item { public ICollection<Tag> Tags { get; set; } public ICollection<Author> Authors { get; set; } public Publisher publisher { get; set; } // other properties... } public class Publisher { public ICollection<Book> Books { get; set; } // other properties... } public class Author { public ICollection<Author> Authors { get; set; } } public class Tag { public ICollection<Item> Items { get; set; } }
I need to return an
IEnumerable<Book>
, with theBook
objects containing allAuthor
,Publisher
andTag
data for eachBook
. Currently, I have the following code, which solves the problem of getting publisher data:public IEnumerable<Book> GetAllBooks() { using (var db = new SqliteConnection(connectionString) { var sql = "SELECT * FROM Books as B " + "INNER JOIN Publishers AS P On B.publisherId = P.id;"; var allBooks = db.Query<Book, Publisher, Book>(sql, (book, publisher) => { book.publisher = publisher; return book; }); return allBooks; } }
How to get the remaining data for a
Book
(ieAuthor
andTag
data with the many-to-many relationships as seen in the schema)? Keep in mind I am new to Dapper and don't know much about functional programming in C#. -
Want to link with my local database using xamarin forms
i want to connect my local sqllite database with my xamarin forms.when i want to connect i create own folder in my system and we cant find out this.pls help me how to connect my local database with xamarin forms application.
-
Assigning the variable as '\ r' instead of taking the value received from the user?
I have a function with some variables defined in it. Variables were defined as static at the top. One of the variables will be taken from the user and an element of array will be equalized to this variable.
like this:
static char[] assign_this_array = new char[1]; static char get_from_user; static void whatever() { Console.Write("enter"); get_from_user = Convert.ToChar(Console.Read()); assign_this_array[0] = get_from_user; }
When the function is first called, it takes the value from the user and makes the assignment. But the second and other times it does not get from the user. When I debugged, I saw that it did not get from the user. When I looked at the get_from_user variable, I saw that '\ r' was assigned. Why is this happening and is there a solution?
-
Save drawn Image to file
I want my programm to save an Text as Image to a file. This is what I could do so far:
Public Sub StringToPrint() Me.Refresh() Dim formGraphics As Graphics = PictureBox1.CreateGraphics() 'draw text to PictureBox1 Dim drawString As String = TextBox1.Text Dim drawFont As System.Drawing.Font = New System.Drawing.Font("Arial", 16) Dim drawBrush As System.Drawing.SolidBrush = New System.Drawing.SolidBrush(System.Drawing.Color.Black) Dim drawFormat As System.Drawing.StringFormat = New System.Drawing.StringFormat() formGraphics.DrawString(drawString, drawFont, drawBrush, New PointF(0, 0), drawFormat) formGraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality formGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit formGraphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality ' Save the screenshot This part right here is not working... 'SaveFileDialog1.Filter = "JPEG Files (*.jpeg*)|*.jpeg" 'If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK _ ' Then ' 'PictureBox1.Image.Save(SaveFileDialog1.FileName, ImageFormat.Jpeg) 'End If 'It says PcitureBox1 is Nothing. drawFont.Dispose() drawBrush.Dispose() formGraphics.Dispose() End Sub
I only want to save the Text in the PictureBox1 as a transparent image file.
-
C snippet Visual Studio 2019
I am having trouble adding a snippet to VS. All of the tutorials out there are for c# and c++.
Please help.
I want to have a snippet where I press 'C' and then this comes up:
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main(void) { return 0; }
-
Binding Source Control Datasource property not responding at design time. VS
I am trying to bind an object to the data source property of a Binding source control but when I click on the property at design time in VS 2019, nothing happens. There seems to be some type of activity because the pc freezes for a short while then nothing happens. Trying this on the same project but different VS version 2017, different machine, brings up the data source dialog, allows to navigate to the data object, select it but the data source property remains empty. It does not attach the object.
-
Mongodb C# - How to get max date - ( Aggregate )
The documents look like this:
{ ContractNumer: 10, SomeField: "ABC", ValueContract: 17.7, DataProcessing: '2021-01-19 10:23:20:10', Status: 1 }
With C# mongodb driver, how do you write something like this?
Select ContractNumer, SomeField, ValueContract, DataProcessing, Status FROM TAB T1 INNER JOIN (SELCT ContractNumer, MAX(DataProcessing) AS MAX_DATE FROM TAB) SUB_T ON T1.ContractNumer = SUB_T.ContractNumer AND T1.DataProcessing = SUB_T.MAX_DATE WHERE ....
So that for each combination (group) of
ContractNumber
we'll get max ofDataProcessing
-
.net core 5 friendly default culture routing
I tried to add multi language feature to my asp.net-core project but there are some changes between .net 3.1 and 5.0 in RequestLocalization and i couldn't get what i want. I added Resource files for each language and I used Resource in my razor pages, its working but there is one unwanted default route bug and i want my routing to work friendly for default culture.
This is what i want,
For default culture (Turkish):
site.com/foo site.com/foo/bar site.com/foo/bar/5
For non-default culture (English):
site.com/en/foo site.com/en/foo/bar site.com/en/foo/bar/5
My other problem is; my route accepts site.com/foo/foo/bar as Turkish culture as well and its not friendly.
My Startup code:
public void ConfigureServices(IServiceCollection services) { services.AddResponseCompression(); services.AddLocalization(opts => opts.ResourcesPath = "Resources"); services.Configure<RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("tr-TR"), new CultureInfo("en") }; options.DefaultRequestCulture = new RequestCulture("tr"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; options.RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider()); }); services.AddControllersWithViews(); services.AddRazorPages(); services.AddRouting(options => options.LowercaseUrls = true); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseResponseCompression(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); var supportedCultures = new string[] { "tr-TR", "en" }; app.UseRequestLocalization(options => options .AddSupportedCultures(supportedCultures) .AddSupportedUICultures(supportedCultures) .SetDefaultCulture("tr-TR") .RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(context => Task.FromResult(new ProviderCultureResult("tr-TR")))) ); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute(name: "culture-route", pattern: "{culture}/{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute(name: "default", "{culture=tr}/{controller=Home}/{action=Index}/{id?}"); }); }
Razor Resource usage and culture change navs
Resource files
How can I solve this or what am I doing wrong?
-
dotnet run error in project from Nuget.targets in asp.net core
I have a asp.net core project which is build for asp.net core 2.2 version. Previously the projects build fine using dotnet run command. But recently when i tried to build my project by running dotnet run command then my projects doesn't builds and gives following error:-
I have tired many solution from following links but cannot find the solution.
Unable to load the service index for source https://api.nuget.org/v3/index.json in VS2017?
Nuget connection attempt failed "Unable to load the service index for source"
Visual Studio - Nuget - Unable to load the service index for source
I Haven't changed any thing in project settings, but getting this error while building. Thanks!
-
accessing httpclient service from within another service in .net 5
I am adding a httpclient as a service (within ConfigureServices(IServiceCollection services)) as follows:
services.AddHttpClient<RequestsClient>(c => { c.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory"); }) .ConfigurePrimaryHttpMessageHandler(() => { return new HttpClientHandler() { UseDefaultCredentials = true }; });
the RequestsClient class is constructed as:
public RequestsClient (HttpClient client, IHttpContextAccessor hca, ILogger<RequestsClient > log, Configuration config)
to use the RequestsClient service in any class/component needing it i'm injecting it as:
[Inject] protected RequestsClient requestsClient { get; set; }
all this works great.
I'm now in need of creating a second service, lets call it "TimedService". How can I use my RequestsClient service from within my second service, TimedService?
injecting it like i do with components won't work as the RequestsClient always is null. is there a way to give TimedService service access to my RequestsClient service?
I'm sorry if this is a stupid question, I'm fairly new to this
-
Bind Collections EF Core
I am about to create a blazor application with ef core. I read the Microsoft recommentation about how to Setup EF Core DbContextFactory
Until now i used in my Razor-Components bindindings to the DbSet like
<select @bind-value="dbContext.People" />
since I read the Article I'm a little confused of how to used it now, because they use the dbcontext inside of a using-Statement.
because of the using statement i cant directly bind a dbset anymore???
@inject IDbContextFactory<DatabaseContext> DbFactory <select @bind-value="dbContext.People" /> @code { DatabaseContext dbContext; protected override Task OnInitializedAsync() { using var dbContext = DbFactory.CreateDbContext(); } }
Whats your suggestion for that?
If i use
<input @bind-value="People" /> @code { ICollection<Person> People; protected override Task OnInitializedAsync() { using var dbContext = DbFactory.CreateDbContext(); People = dbContext.People; } }
nothing will be displayed. The Debugger tells me:
Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. Object name: 'DatabaseContext'.
-
Blazor server side performance issues
Its a Blazor server side project with about 100 .razor pages, When a change occurs on one of the pages, it takes about 19 seconds to rebuild pages, restart IIS Express and refresh the page. It's awful, I make only a minor change in html, but it takes long time to show the results. The test result is like this :
With 100 razor pages and all css and js references
build : 10 sec
refresh page : 19 sec (include 10 secs for build)When we remove 90 pages of 100 pages (10 pages remains) :
build : 3 sec
refresh page : 12 sec (include 3 secs for build)When we remove all css and js references :
build : 3 sec
refresh page : 6 sec (include 3 secs for build)It is not good at all, because the project is growing and finally we will have about 400 pages! and extra css and js references will added. In this case, the time will be much longer for developing.
what's the solution? Thanks
-
Cannot Migrate Blazor App to .Net 5 Due to System.Runtime Error
I have been working through an awesome tutorial within Udemy to learn more about Blazor (https://www.udemy.com/course/programming-in-blazor-aspnet-core/), but have hit a stumbling block that I'm not entirely sure what to do with.
Short Version
When upgrading to .Net 5 from .Net Standard 2.1, I end up with this error when trying to run this sample Blazor application as soon as it loads up (so it's not hitting any of my code):
System.TypeLoadException: Could not resolve type with token 01000014 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
I see a similar problem with this SO link, but it didn't really give me much to go off of.Detailed Version
With prior versions of .Net, you installed the latest, then Visual Studio picked that up, you switched projects and away you went - everything was seamless and just worked. With some of the newer stuff though, Microsoft's messaging has been extremely confusing and the problem I'm hitting now is inside that Udemy tutorial I need to utilize the
IJSObjectReference
interface to do something. When I first added that to the code, the type reference couldn't be resolved so a quick search pointed me to needing to move the project to .Net 5 by changing this:<PropertyGroup> <TargetFramework>netstandard2.1</TargetFramework> </PropertyGroup>
to this (because Visual Studio doesn't always show .Net 5 as an option):
<PropertyGroup> <TargetFramework>net5.0</TargetFramework> </PropertyGroup>
Seemed simple enough, so I changed the Client Blazor project to this and tried to compile. That gives me this error:
Project BlazorMovies.Client is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project BlazorMovies.Client supports: net5.0 (.NETCoreApp,Version=v5.0)
. I figured okay, I'll bump Server to 5.0 next and then everything compiles fine, but as soon as I pull it up, I get this error:System.TypeLoadException: Could not resolve type with token 01000014 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
. Then I remembered not recalling if I'd installed .Net 5 yet, so I went to check and (via docs.microsoft.com) I only have 4.8.03752 installed. I then did some searches to try and find the .Net installers and there were multiple (see here) - even the layout of the page is really overwhelming, with ~20 install links scattered throughout. I knew I needed at least x64, so I first installed the SDK since it said Visual Studio support and that went significantly faster than I expected (based on prior installs of .Net), but now VS is showing .Net 5 which seemed promising! I re-checked the registry though, and it still says 4.8.03752 and when I went to Add/Remove programs, .Net 5 doesn't show up like all the other versions. I next installed the Hosting Bundle which said it was successful, but the sample app still has the exact same error.Any advice? I know Blazor is quite new, but with Microsoft's extremely confusing messaging between .Net Framework, .Net Standard, .Net Core and now a migration back into .Net 5 that seems to need multiple installers, I don't really know where to go next. That error is entirely generated from within the Web Assembly code according to the stack trace, so it doesn't appear to be anything related to what I'm doing. Here's a screenshot of everything Chrome shows me in the console:
-
Blazor WebAssembly PWA loses functionality and style in DevOps Pipeline
When first opening the application or after doing a hard reload the isolated CSS does not load. The same is if you open up the application on mobile. In addition, the promps to download the PWA doesn't show.
What I have is a Blazor WebAssembly PWA. The solution has two projects 'server' and 'client'.
The server project contains the start up, caching etc.
The client contains the frontend.The solution is hosted in an Azure App Service (Deployment Slot).
If deploying manually to the slot everything is fine. (Download the publish profile from Azure AppService and publish server project)
Now to the problem:
I set up two pipelines, a build pipeline and a release pipeline.The build pipeline:
trigger: - master pool: vmImage: 'windows-latest' variables: solution: '**/*.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' steps: - task: NuGetToolInstaller@1 - task: NuGetCommand@2 inputs: restoreSolution: '$(solution)' - task: VSBuild@1 inputs: solution: '$(solution)' msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"' platform: '$(buildPlatform)' configuration: '$(buildConfiguration)' - task: VSTest@2 inputs: platform: '$(buildPlatform)' configuration: '$(buildConfiguration)' - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' ArtifactName: 'drop' publishLocation: 'Container'
The release pipline (Has some CI/CD settings)
Due to building a solution with multiple project I get multiple Zip-files in my drop artifact. The server one is the one I pick up and deploy to the same AppService.
The pipelines work. The problem arises first when the application is opened. If I publish manually everything looks fine and I get the prompt to download the app. However, if I use the pipeline neither the correct CSS is loaded (at least not the isolated) or the prompt to download the PWA is shown.
-
JetBrains Rider or Dotnet Core Cache issue with Blazor WASM
Blazor WASM, I have to clean my project every time I make a change to an Blazor class library. IF I don't it's EXTREMELY unreliable if my browser will show the updated version (sometimes it works, sometimes not). This is an absolute horrible development experience considering it takes 2 or 3 minutes to recompile everything every time.
Does anyone else have this issue? How could this slip through the cracks of the dotnet team and JetBrains. Surely I'm not the only one with the issue. Is there a way to fix this?
Yes, I'm using JetBrains Rider on a Mac.
Thanks in advance.