How to use .net 6 with MySQL - mysql

Create a project in Visual Studio.
Open Program.cs
Replace:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
For:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(connectionString, new MySqlServerVersion(new Version(5, 7))));
Visual Studio will advertise you for an error.
Accept the suggestion and install package "Pomelo..."
Open appsettings.json and replace the SqlServer DefaultConnection with your MySQL values.
Something like:
"DefaultConnection": "server=your.server.com;user=your_user;password=your_pw;database=your_dbname;port=3306"
remove-migration (all of them)
add-migration
update-database
Done
Everything else works like the same.

Make sure you are using
<PackageReference Include="MySql.EntityFrameworkCore" Version="6.0.4" />
see:
https://www.nuget.org/packages/MySql.EntityFrameworkCore/6.0.4#dependencies-body-tab
(to make it clear, make sure you are NOT using the below (similarly named, but abandoned)
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.22" />
See
https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/
2.
Consider a change (which is my personal preference between the two)
https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql
Bonus tip:
When "fishing" at nuget.org .. always look at the "Dependencies" and "Frameworks" ("tabs" on the gui of nuget page)....
https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql#dependencies-body-tab
Bonus Tip #2.
Always post your csproj contents with dependency questions. At least the germane portions of your csproj files.
Extra:
See my answer here:
Cannot find the UseMysql method on DbContextOptions
There are "cAsE iSsuEs" with the MySql/MYSQL using statements to watch carefully.

Related

How can I set the output path of a vc++ project different than its dependencies (nuget)?

Premise
I have a Visual Studio 2015 solution containing different VC++ projects.
Some of them (EXE and some DLLs) have the $OutDir set to default "$(SolutionDir)$(Configuration)\" (i.e. "C:\MySolution\Debug\").
For some other projects (DLLs), I need to change the output path to a sub-directory of the "default" $OutDir (i.e. "C:\MySolution\Debug\Pieces\".
Example directory tree:
C:\MySolution\Debug\
MyProgram.exe
Dependency.dll
.\Pieces\
MyPiece1.dll
MyPiece2.dll
Constraints
the "Pieces" DLLs depends on a third-party Dependency.dll (through NuGet package), which I cannot modify.
Usual solution
The usual way for this is to change the $OutDir project setting for "pieces" projects, but this will also force their dependencies to be output in the same sub-dir.
This is not wanted and also created problems in debugging and packaging of the entire solution.
What I tried so far
I tried to:
1. keep the $OutDir the same for all projects
2. change the "pieces" $TargetName to "Pieces\$(ProjectName)"
This seems to work (both MyPiece*.dlland Dependency.dll are correctly placed and debugging is fine), but unfortunately Visual Studio generates the following warning:
warning MSB8012: TargetName(Pieces\MyPiece1.dll) does not match the Linker's OutputFile property value (MyPiece1). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
This warning is somewhat confusing, because the %Link.OutputFile in the project settings looks correct:
$(OutDir)$(TargetName)$(TargetExt) => C:\MySolution\Debug\Pieces\MyPiece1.dll
Question
What is the correct approach to solve my problem?
How do I force Visual Studio to output some of the generated files in a different path, but still having their Nuget dependencies in the "default" $OutDir?
I've searched the web and StackOverflow already, but I can't find a suitable answer.
Note: my problem is not related to upgrading a pre-VS2010 solution (as in Microsoft official notes on warning MSB8012 after solution upgrade and asked on StackOverflow).

Monodevelop fails to build, can't find Microsoft.DiaSymReader.Native.x86.dll'

I am trying to build a web api project using monodevelop on a mac. The thing is that after a few hiccups (explained in a question that turned out to be so messy I have just deleted) I get to the point of getting this error
/Users/myuser/git/LiveData/LiveData/CSC: Error CS0041: Unexpected error writing debug information -- 'Windows PDB writer is not available -- could not find Microsoft.DiaSymReader.Native.x86.dll' (CS0041) (LiveData)
In a windows machine the same project builds using visual studio targeting mono 4.5.
When I click on the error it tells me that /Users/myuser/git/LiveData/LiveData/CSC doesn't exist
Another thing is that in the folder structure of the solution there's a package folder (not the one inside the project) and inside this one I have a folder called Microsoft.Net.Compilers 1.3.2 that has inside another folder called "tools" that contains among other things csc.exe and the dll thta can't be found.
I have tried to install the dll directly in the project using nuget but even if it was installed the build showed me the same error
Thanks,
As for workaround for now you can just limit usage of Microsoft.Net.Compilers to Release configuration (edit *.csproj file):
<Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="'$(Configuration)' == 'Release' And Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />
take a look at beginning of condition:
'$(Configuration)' == 'Release'
This way I can build and debug locally and build my project ie. in appharbor.
Building the project in release configuration should fix it!
This might not be completely related but may be helpful in some ways. Regarding the issue on 'could not find Microsoft.DiaSymReader.Native.x86.dll', have a look at this issue on GitHub: https://github.com/dotnet/cli/issues/3016
It seems like the solution is either:
Dependency to Microsoft.NETCore.Platforms needed for RID graph which
was missing. Any package which has transitive dependency on it (like
NETStandard.Library) could also make things work.
Adding dependency to "Microsoft.NETCore.Platforms": "1.0.1-" or
"NETStandard.Library":"1.5.0-" make it work.
adding Microsoft.NETCore.Platforms works as well

Msbuild running in Jenkins target calling HgPull fails with HgProcessException: The command <hg.exe> is not available

I am porting over an MSBuild script from CCnet to run in Jenkins. The MSBuild project is used to create a deployment package. I would rather have Jenkins drive this process itself but that's a longer term aim.
The problem i am having is (as in the title) when we try and use the HgPull target, from the MSBuild mecurial task (http://msbuildhg.codeplex.com/) we get the error message
HgProcessException: The command hg.exe is not available [Path to project]
I have seen on the project web site that someone solved it by adding the LibraryLocation proeprty to the target but that seems to have made no difference. My target currently looks like this:
Target Name="UpdateSources">
<HgPull
LibraryLocation="C:\Program Files\TortoiseHg\hg.exe"
Force="true"
Update="true"
LocalPath="$(SourcePath)"
/>
<HgUpdate
LibraryLocation="C:\Program Files\TortoiseHg\hg.exe"
Clean="true"
LocalPath="$(SourcePath)"
/>
I'm rather at a loss. Please let me know if you need any more information added to this post to solve this issue. I'm really quite new to MSBuild so really not sure where to start investigating this.
EDIT:
One thing i forgot to mention was that i have tried running the MSbuild command in a console window on the build server and still get the same result. This is really odd given it works fine in CCNet, what magic is CCNet doing to make this command work?
This is now resolved, unfortunately i'm not sure what changes i made to correct these. I believe it may have been down to path separators and whether they where trailing or not in another part of the config file. It does so annoy me with the lack of resilience/consistency between applications where you need to specify paths with/without trailing slashes.
Just a thought, but try adding 'C:\Program Files\TortoiseHg' to your system path. Maybe CCNet has it specified somewhere that Jenkins doesn't have access to.
Also, just for sanity's sake, verify that hg.exe actually exists at that location.

Can I use configuration name in pre and post-build-events?

In Codegear RAD Studio 2007, I'm trying to do some file deletion and copying during the pre-build and post-build events that involve folders named after the current configuration. In Visual Studio, this is easily done with the $(ConfigurationName) macro.
Is there any equivalent to this in RAD Studio? If not, is there a workaround I can use?
I think what you're looking for $(Config). For example, in a prebuild event, you can add echo $(Config) and it will print a string like "Debug" or "Debug Build". I've tested it in Rad Studio 2010, but not in 2007. I believe they use the same configuration variable, though.
If that doesn't work, open a cbproj file in an editor and look for something like this:
<Config Condition="'$(Config)'==''">Debug</Config>
Whatever word appears instead of 'Config' there may give you a clue.

Is it possible to browse the source of OpenJDK online?

Is it possible to browse the source code of OpenJDK online, just like I can do with SourceForge's projects? I never used Mercury before, so I felt confused.
(Note: I don't want to download the source. I just want to browse it online, to see how some methods are implemented.)
OpenJDK is now on GitHub: https://github.com/openjdk/jdk
It is a large project, but you will find the implementations of the core classes under jdk/src/java.base/share/classes.
For instance you can find the implementation of java.util.List here.
If you need to browse older versions, you still need to use the old Mercurial interface.
The Mercurial interface there is quite confusing if you are not used to it, and since this is a large project, it can be hard to find what you are looking for.
Here is an example:
To find the JDK6 implementation java.util.List, select jdk6, jdk, select browse. Then browse to src/share/classes/java/util/List.java.
You should end up at http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/tip/src/share/classes/java/util/List.java
The latest JDK 8 OpenJDK Java Class Library source code can be found here: http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/tip/src/share/classes/
Here is the basic step to get latest or any released version of Openjdk 8 (or any existing java version) source code, and use them in Eclipse.
Steps:
[browse source]
Open url for jdk, e.g http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/
click tags
choose proper tag, e.g jdk8u73-b02
then click browse,
then browse into folder src/share/classes,
[download source]
then click one of bz2 / zip / gz, to download source in relevant compressed format, (e.g for jdk8u73-b02 in zip format, the url will be: http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/archive/2ab13901d6f1.zip/src/share/classes/)
[use in eclipse]
uncompress it,
zip the folder "classes/", make "classes/" as the root dir of .zip file, (e.g first cd jdk-2ab13901d6f1/src/share/, then zip -r openjdk_8u73_b2_src.zip classes/)
move the created zip file to proper location, it will stay there for a while, (e.g mv openjdk_8u73_b2_src.zip /media/Eric/software/java/jdk/openjdk/openjdk8u73-b02/source/)
in eclipse, specify source file for jars of installed jre, could specify the source attachment for each jar of installed jre respectively, the most common jar is probably rt.jar,
optionally, might need refresh project to make it totally take effect, not sure is that necessary,
test it: in eclipse, ctrl + shift + t, then input Cancellable, select the sun.nio.fs.Cancellable of corresponding installed jre,
if the source code is available, then it's good, because this source is not available in jdk_home/src.zip, it must be from the additional openjdk source,
switch source back: could switch back to use "jdk_home/src.zip", if don't want to use the external openjdk source,
ok
Here's a way to browse the repositories and look at just the bits you want.
http://hg.openjdk.java.net/
Is that what you are asking?
Append a "/file" to the root URLs to view the browser like this:
http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/
http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file
Grepcode.com is great for similar things - not only OpenJDK sources, with searching in classes/methods and links between classes directly in highlighted code:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/java/net/Socket.java
As mentioned in the other answers, the source code repository is at https://hg.openjdk.java.net
However, the OpenJDK team mirrors some of the projects on GitHub: https://github.com/openjdk
Including the latest Java version project (https://hg.openjdk.java.net/jdk/jdk): https://github.com/openjdk/jdk
Surely http://hg.openjdk.java.net is one good option. The other equally good source is zGrepCode https://zgrepcode.com/java/openjdk/ . It has both Open JDK and Oracle java versions.