ASP .NET Core builds project on every item add, how to disable - asp.net-core

I have hard times on migrating one of our enterprise MVC projects to Core 2.1.
I want to move the project to the new structure Razor Pages + View Components from Controllers + Views/Partials. We have a ton of models and components and actions there.
When I convert projects I usually move things around, copy items to new paths, run automated refactorings, create new/change classes to fit the new requirements and design and that BREAKS the project. A build is the last thing I do when everything is already setup, just to see if I missed something.
Now after few refactorings and breaking changes I can't add new items(razor pages, view components and so on) just because project is not buildable.
"There was an error running the selected code generator: Failed to build project..."
Basically it forces me to do everyting manually, check every copied/migrated piece of code just to add a new item !
I'm in nightmare, please someone wake me up, how to disable this thing ? or suggest a migration strategy for large projects.

First, and most importantly, adding a item via scaffolding will always kick off a project build. The scaffolding needs the project to be in a consistent state in order to function correctly. There is no way around this.
Aside from that, Visual Studio will only rebuild on changes if you're actually running the site. So if you've got it running in IIS Express, kill it to avoid that.
For what it's worth, it's better to correct errors as you go, anyways. It much easier to process a few errors at a time than hundreds all at once, and you'll also then be able to take advantage of Visual Studio's refactoring features, which only work when the project can build, making the total amount of work you have to do usually far less.

in MVC:
Add -> View adds scaffold without build
in Core:
Add -> View adds scaffold + build
Add -> New Item -> View adds without build
So if you don't want to run build on every single add in Core use
Add -> New Item -> ...

Related

How to execute the "AL:GO!" task as part of a script

Recently, my company started to focus Extension_v2 development for Dynamics NAV BC. We store our code in an internal Git-Server. So far, so good.
But startig a new project is still a very fiddly task. You have to create a repository, clone it, execute the AL Code-Task, move the files to the fitting location push the repository to the correct upstream etc. And all this does not include the first initial Steps (README, CHANGELOG and all other fundamental files...).
So I wanted to write a small PowerShell-Script, to do all these initial steps before being able to start working on the Project.
The Problem: I could not find a way to execute the "AL-GO!" task via script.
I have already searched the Internet and some forums for an answer... but it seems like microsoft did not consider the possibility to execute tasks from the AL-Language-Extension via script.
I also played around with the New-NAVAppManifest and the New-NAVAppManifestFile command for the old Extension_V1 development, but that did not do the trick.
I am looking for a fair and easy way to combine the creation of the app.json file and the launch.json file with other commands to easily initialize a new Project without haveing to write all commands manually. Maybe I did not recognize the easy solution. Or maybe this is just the way we have to do it in Extension_v2.
Anyway, thanks for all your help nevertheless.
Greetings.
Stay away from Ext V1. It's highly deprecated at this point.
First of all, why do you need to execute the "AL-Go!" via script? The "AL-Go!" command should already include all necessary steps to create an empty project including the launch.json and app.json. (minimal adjuments required dependent on your BC environment)
There is an extension/plugin for Git in Visual Studio Code which will handle all the repository stuff for you. You don't need to change file locations if everything is set up for Git. I rarely use it yet, but saw a demo for it on the Directions EMEA last year and I'm pretty sure it works at its current state (someone correct me if I'm wrong)
A way to implement the "AL-GO!" command for a script or for setting up additional steps in your project setup might be to write your own visual studio code extension/plugin which requires some additional know-how for that.
OR
You just change the settings/files of the default project, I bet there is at least a file for creating the initial AL project. Just change that to your requirements

Add individual user accounts

I am developing a project in ASP.NET CORE, it is already in progress, and there arose the need to create the login, however how to do this with the project already in progress? How to enter as Indivual User Accounts? I've seen several tutorials, but always starting from scratch, a new project, and the project is already started. What's the best way out?
On a general note, with modern frameworks that provide generators/scaffolding I sometimes end up just running the examples and then do a recursive compare between the existing project and the new project.
I can then carefully apply the necessary patches to bring the changes into the existing project
(This is useful for a number of things, - something I use it for more frequently is to bring a forgotten project up to date and streamline it.)
In ASP.NET Core 2.1 you can scaffold out identity into existing projects. See this guide on how to do this.

TFS Build XAML Template at “AssociateChanges” step get all the Work Items since begging of the source code branch created

I have asked a similar question
TFS Build Configuration: get all the Work Items Details for a particular build
And based on the answer of above question I have the below query. I decided to start a new thread for new question rather than confusing people in same thread.
I am using a default XAML template for workflow of TFS build configuration. Now my requirement is that I need all the Work Items since beginning whenever I trigger a build event for any build definition regardless of last successful build.
Let say I have triggered first TFS build and it is succeeded then I triggered 2nd build and that is also succeeded.
Then I have opened the log file of 2nd successful build and goes to Diagnostics Tab of last build. Inside Diagnostics tab there is a section as “Associate the changesets that occurred since the last good build”
Inside this it will display a message like
"No change sets are submitted to build 'ABC…..'"
Whereas I require list of all the work items since beginning.
Please suggest me the changes which need to be done in XAML template so that I can get all the work items since the beginning of source code.
As we know, associate the changesets and work items only occurs since the last good build.
There is a simple workaround to achieve what you want, you can specify a previous changeset to queue a build, then build the latest changeset again, then you'll get the associated changesets and work items again. Refer to this blog: http://chamindac.blogspot.sg/2013/09/tfs-2012-get-release-build-with.html
Otherwise, you need to create a MSBuild custom task that makes a call to TFS for the items. Check the links below:
https://volatilecoding.com/2013/06/11/tfs-build-how-to-customize-work-item-association/
(this solution is for TFS2010/TF2012 build process template, you'll
need to work on TFS 2013 build process template).
http://devgorilla.net/?p=104

How to execute arbitrary line of code in TFS build process?

I am creating a custom process template in our TFS server.
I would like to execute the following line of during the process, to automatically modify the assembly's revision number in AssemblyInfo.cs based on the current MMDD:
File.WriteAllText(file, Regex.Replace(File.ReadAllText(file), "(?<=\[assembly: AssemblyFileVersion\(""[0-9]*.[0-9]*.[0-9]*.)[0-9]*(?=""\)\])", Function(m) DateTime.Now.ToString("MMdd")))
Unfortunately I cannot find out how to execute an arbitrary line of VB.NET code in the build process. There are no code activities called "execute", "run" etc.
I tried to hack it by inserting a lambda function into a WriteBuildMessage() call, but found that lambdas are disallowed:
(EDIT: after other problems with that expression were fixed, it now simply gives the error: "Statement lambdas cannot be converted to expression trees" - ergo I can't do what I'm trying to do here. If "File.WriteAllLines" was string instead of void then I could return it and be laughing.)
Is there a way I can execute an arbitrary line of VB.NET code as part of the build process?
Note: I got around it by adding a node to InvokeMethod directly on System.IO.File.WriteAllText, passing the Regex.Replace call as one of the parameters.
I'll leave the question open in case anyone can provide a direct answer to the original question.
As you mentioned yourself it is possible to use the "InvokeMethod" in order to somewhat execute a line of code.
What I would suggest is to create a custom activity where you can provide it with the parameters, such as the file name and file path.
In order to achieve this two main tasks are needed:
Include a custom build process template
Creating a custom activity
You either do this in your current solution or you create a whole new solution to handle your custom activities and process template.
Include Custom Build Process Template
Whether you choose to work on your current solution or a new one, it is important to have the Process Build Template included in a separate project.
The project needs to be an "Activity Library" which is found under installed (VS 2013):
Right-click solution -> Add.. -> New Project... -> Visual C# -> Workflow
In this project you add your process template that you have been working on, by adding it as an existing item and making it a link. This can be done by pressing the small arrow at the "add" button
When this is included you will need to include several references, which can be found here [1]
Creating Custom Activities
As for the Build Process Template all the custom activities needs a project to be build in. This is to ensure that when they are to be used it is simply referencing the project or including the dll.
This project also needs to be an Activity Library, where this time the activities are to be created.
An activity is a Code Activity and can be created by:
Right-click Project -> Add -> New Item... -> Visual C# Items -> Workflow -> Code Activity
And again this project needs several references in order to build, which can be found here[1]
References:
For more information and ideas take a look at this:
[1]: Ewald Hofman - Customize Team Build
You should not create this yourself. You should use the precreate TfsVersion activity built into the TFS Community Build Tools.
https://tfsbuildextensions.codeplex.com/wikipage?title=How%20to%20integrate%20the%20TfsVersion%20build%20activity&referringTitle=Documentation
This tool will do all of the heavy lifting and is supported by the Visual Studio ALM Ranger and MVP's.

Could not load type 'System.Data.Entity.Core.Mapping.EntityContainerMapping'

When I debug the following code, I receive the message "System.TypeLoadException was caught" when I perform the Delete().
Using db As New ScholarshipEntities
db.ApplicationHistories.Where(Function(h) h.HistoryTypeId = 0).Delete()
db.SaveChanges()
End Using
I am using EF 6.1 in Visual Studio 2013. I also have the EntityFramework.Extended library installed.
I have no trouble querying results. I thought the bug might occur when the Where method has no results, but that is not the case. I also have no problem adding new models (.edmx), which was a problem some people with this exception had.
I just recently upgraded to EF 6.1 and installed the Extended library. This is my first time using one of the extended methods. I've un-installed and re-installed the nuget packages with no success.
IntelliTrace shows the following exceptions from the Delete() call (in order):
'EntityFramework.Reflection.DynamicProxy' does not contain a definition for 'InternalQuery'
Cannot implicitly convert type 'EntityFramework.Reflection.DynamicProxy' to 'System.Data.Entity.Core.Objects.ObjectQuery<Scholarship.ApplicationHistory>'
Could not load type 'System.Data.Entity.Core.Mapping.EntityContainerMapping'
I've added an issue on the Extended library's github.
Update
I've reinstalled EF and the EF.Extended library with no luck. I am able to use RemoveRange in its place. I am able to create a new project, install the packages, add a model mapped to the same database, and successfully use Delete. Obviously, the problem is in my current solution.
In my solution, I have an ASP.NET project and a regular library project. In the ASP project, a page's code behind calls a method in the library RemoveHistory. The library contains classes for the business logic and data access. Both classes implement interfaces. The actual Delete occurs in the data access class. My model also resides in this library project.
I may be able to create a completely new project and bring everything over, but that will take quite some time. Even if I did, I want to understand why it doesn't work in the first place, so that I don't have to repeat this process.
If you want to delete certain rows do it like that:
Using db As New ScholarshipEntities
db.ApplicationHistories.RemoveRange(db.ApplicationHistories.Where(Function(h) h.HistoryTypeId = 0))
db.SaveChanges()
End Using
If you want to remove single entity do it like that:
Using db As New ScholarshipEntities
db.ApplicationHistories.Remove(db.ApplicationHistories.Single(Function(h) h.HistoryTypeId = 0))
db.SaveChanges()
End Using
I "solved" the issue some time ago. I'll eventually go back to try and reproduce the problem to confirm my suspicions.
There were multiple versions of Entity Framework installed in the solution. This didn't appear to affect basic EF functionality, though I'm sure it did in some subtle, potentially buggy fashion.
Every time the solution was opened, NuGet would state that it couldn't complete uninstallation. Uninstalling and restoring via NuGet was unsuccessful, and the packages had to be deleted manually. Once completely removed, I installed the packages again. This resolved the issue.
I wish I could give a more technical answer, though the basic reason was forgetting to look closer at the packages folder and configuration.