Can I build multiple projects with dotnet build? - .net-core

Can I somehow build multiple projects with one root project.json file (or otherwise)? For example, one library, one test project, and one command line? If so, how?

I may be one year late in answering, but may be it is still useful for somebody who lands here after this.
dotnet build no longer uses project.json, instead uses *.csproj. And dotnet build can now take a directory name as an argument, and uses the *.csproj within that directory for the build. This being the case, the easiest way to build from a top-level-directory goes like this:
Assuming the structure of your projects is:
src
|
+ -- proj1
|
+ -- proj2
|
+ -- proj3
|
.
.
Just go to the top-level directory (src in this case), and type this:
Get-ChildItem -exclude ".vscode" | %{Write-Host -ForegroundColor DarkMagenta "Building $_..."; dotnet build $_;}
I normally use PowerShell within VSCode, and hence you see the -exclude ".vscode" and PowerShell commands Get-ChildItem (aliased also as simply 'dir') and Write-Host.
Hope this helps.

If all of your projects are stored in a structure like this :
<root>/src/Project1
<root>/src/Project2
then you can use a single command with a globbing pattern to build all of the projects at once:
dotnet build src/**/project.json
From what I am aware of, you'll still need individual project.json files for each project though.

Go to the root of your solutions and run the following PowerShell (only for .NET Core projects)
$baseDir = (Get-Item -Path ".\" -Verbose).FullName
Write-Host ("Scanning *.sln files in " + $baseDir)
$solutionPaths = Get-ChildItem -Path $baseDir -Include *.sln -Recurse
Write-Host ("Total found: " + $solutionPaths.Count)
foreach ($solutionPath in $solutionPaths) {
Write-Host ("Building => " + $solutionPath)
dotnet build $solutionPath
}

Related

What command can I use to remove a project in .NET Core?

What command can I use to remove a project in .NET Core?
The project I want to remove was created with the help of the command:
dotnet new webapi
Is it true that there is still no command for this? It was pointed out here.
When you run the command dotnet new [type], dotnet will create a project in whatever folder the current working directory is. (where [type] will be something like console or webapi)
You never want to run this command without first creating a sub-directory and changing to it or you will have a mess of files sitting somewhere you will wish they weren't. The amount of files and their names will depend on the type of project you are making.
If you make this mistake and don't know which files to delete, you can delete them individually.
Create a temporary directory and change to it.
Run the same dotnet new [type] command in that directory.
Looking at the files created in step #2, you will know what to delete.
If you made a sub-directory to begin with, you can simply:
(windows)rd /s /q <dirname>
(linux)rm -rf <dirname>
to clean up the mess.

.NET Core: How to create solution folders from the command line

I am organising a new project, and I would like to create as much of it as possible from the command line.
I like to put my test projects into a solution folder. However, the command dotnet sln add seems somewhat restricted. Its argument list seems to consist only of a list of project files to add.
Is there a way of specifying a solution folder (as opposed to a physical folder) when adding newly created projects (test projects in my case, but the question is more general)?
From this Microsoft Docs
dotnet sln yoursolution.sln add pathofyourproject\yourprojectfile.csproj --solution-folder solutionfoldername
If the solution folder doesn't exist, this command create a new solution folder. In the other cases, this command add a project to your solution folder.
I just accomplished this using .Net Core 2.2 by adding a new project to Tests\UnitTests\UnitTests.csproj folder first, then running the dotnet sln add from the solution root.
Initial Folder Structure
Adding UnitTest.csproj inside Tests\UnitTests
Ran from folder containing TestMvcCore2.sln
dotnet new classlib -o .\Tests\UnitTests -n UnitTests
Adding UnitTest.csproj to TestMvcCore2.sln
Ran from folder containing TestMvcCore2.sln
dotnet sln add .\TestMvcCore2.sln .\Tests\UnitTests\UnitTests.csproj
Creates a Tests solution file in the visual studio sln
At the moment it is not possible, you need create the physical structure folder like the solution structure folders
dotnet new <typeproj> --output "physical/domain" --name "domain"
dotnet new <typeproj> --output "physical/service" --name "service"
after open the solution with visual studio, create the "physical" solution folder and add the previous projects that you already have ready
As mentioned in Microsoft Docs, if you want to create new solution, you have to write dotnet new sln. This command will create a solution file in current directory named with the name of current directory. Also, you can specify the name of output solution file by dotnet new sln -o <SOLUTION_NAME>. This will also create a folder with the name you specify. To add projects to this solution enter in command prompt: dotnet sln <YOUR_SOLUTION_NAME> add <PROJECT_YOU_WANT_TO_ADD> <PROJECT_YOU_WANT_TO_ADD> <PROJECT_YOU_WANT_TO_ADD> ... This will add all the projects you've specified with its folders to the solution you've specified.

How to organize multiple projects in an ASP.NET CORE solution like DDD?

How to create a solution of .net core?
For example:
1 Web Project
3 Lib Projects
How to create it without Visual Studio?
Using VS Code or Sublime Text?
If you have dotnet core installed just create a root folder for your solution. Then open terminal in root folder and type for a mvc project:
dotnet new mvc -o SolutionName.Web
remember -o parameter creates a folder for new project and if it was -n project was going to be created in the folder you are in.
and for class library project
dotnet new classlib -o SolutionName.Library
cd SolutionName.Web
this line to add reference to use this library.
dotnet add reference ../SolutionName.Library/SolutionName.Library.csproj
get to root folder again
cd..
dotnet new sln -n SolutionName
we talked about -n. After we created solution we will add projects to solution.
dotnet sln add SolutionName.Web/SolutionName.Web.csproj
dotnet sln add SolutionName.Library/SolutionName.Library.csproj
dotnet build
if you are using vs code just type
code .
in the root of solution in terminal and you will start coding.
Here is an example project referenced from Microsofts Docs website (https://github.com/dotnet-architecture/eShopOnWeb). As you can see, inside of the src folder they break up the 'solution' into three 'projects', 'web', 'infrastructure' and 'applicationCore'.
This is one way to do it using PowerShell and the dotnet command line interface.
Create directories for the Web and Lib projects.
New-Item -Type Directory Web
New-Item -Type Directory Lib01
New-Item -Type Directory Lib02
New-Item -Type Directory Lib03
Create the Web Project
cd .\Web\
dotnet new --lang C# --type Web
cd ..
Create the three Lib projects.
cd .\Lib01\
dotnet new --lang C# --type Lib
cd ..
cd .\Lib02\
dotnet new --lang C# --type Lib
cd ..
cd .\Lib03\
dotnet new --lang C# --type Lib
cd ..

Robocopy everything in subdirectory excluding the root files

How do I use robocopy so the root contents are not copied?
I already have root files stored elsewhere and I just would like to copy the sub directories and their contents while the source folder still containing root directory contents.
This is not possible with native robocopy switches as far as I can tell. You will need to use a script to enumerate the subdirectories and run robocopy against them.
Here is a sample PowerShell command that will accomplish what you want, copying everything from C:\temp\source\ to c:\temp\target\, excluding the files that are in c:\temp\source:
get-childitem c:\temp\source\* |?{$_.PsIsContainer} | %{robocopy $_.FullName c:\temp\target\$($_.Name) /S}
Credit to powershell ignore files in root but robocopy folders and their contents for the basics of this.
I don't have a reputation but the answer Mr. Hinkle gave solved 2 days of effort and searching. My challenge was moving the files that were > 1hour of age. This combination of powershell and robocopy appears to work. Below is my final code.
# Clear screen
cls
# Disconnect the drive if it exist - don't know where it is pointing to
If (Test-path p:) {
net use p: /delete
}
#Map the destination
net use p: \\server\dir1\dir2\dir3 password /USER:domain\user /P:no
get-childitem -path 'D:\dir1\dir2\' |
where-object {$_.LastWriteTime -lt (get-date).Addhours(-1)} |
?{$_.PsIsContainer} |
%{robocopy $_.FullName p:\$($_.Name) /S /MOVE /r:3 /W:1}
net use p: /delete

How to copy/update resources, frameworks or plugins to the (Mac OS X) "app bundle" with Qt Creator or qmake

I've been reading for a couple days on how to copy/update external resources, plugins or frameworks to my App's Mac Bundle using Qt creator or qmake.
Right now I have found two main solutions. One is to use qmake together with some commands on the ".pro" file. The other one is to do a "Custom Deployment Step" script.
I was hoping to use the second option cause I already had a small make script that did what I wanted. The problem is that Qt Creator offers so little variables to work with that the script lost its usefulness. For instance, my script uses the "Target App Path" as a parameter so it can do all its work from there. But please correct me if I'm wrong, Qt Creator only offers %{buildDir} and %{sourceDir} variables...
The other option is using qmake. These are the things that I have tried so far on my ".pro" file:
1) Using the INSTALL command. I did a small test where I tried copying some files this way:
MediaFiles.path = test/media
MediaFiles.files = media/*
INSTALL += MediaFiles
And basically nothing happend. I was hopping to find the same "media" folder on the "test" folder but nothing. Don't know if I'm doing something wrong.
Please note that the "media" folder is beside the "test" folder and the ".pro" file. (They all have the same hierarchy position.)
2) Then I tried QMAKE_BUNDLE_DATA:
MediaFiles.path = Contents/MacOS
MediaFiles.files = media/*
QMAKE_BUNDLE_DATA += MediaFiles
But this gave me the following error:
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
make: *** [PathToApp] Error 64
None of the solutions seem to be pleasing so far. If I wanted to do a good custom make script I will need to hardcode every target path separately. In my case I have 8 different target path depending on some "CONFIG" variables.
I'm sure the qmake solution are the official way of doing this. If someone can point me out the solution to the Error 64 would be cool.
Some further question:
Do I have to do a qmake every time I want to update my bundle?
Can I execute my make script with the qmake?
QMAKE_BUNDLE_DATA started working flawlessly after putting the command on the end of the .pro script.
mac{
MediaFiles.files = media
MediaFiles.path = Contents/MacOS
QMAKE_BUNDLE_DATA += MediaFiles
}

Resources