I am writing a bat script to create a project directory and then create dotnet projects. In the script, I try to access the csproj file through referencing it. The issue that I am having is that the directory name is not being pulled in. My bat script takes two inputs, the project directory and project name.
echo %1
md %1
cd %1
echo %2
::Create Directory Structure
md src
md documentation
md "documentation/SystemDocuments"
md "documentation/Diagrams"
::Create Solution Structure
cd src
dotnet new sln --name %2
dotnet new console -o %2
set "test=%2%\%2%.csproj"
echo %test% :: This value is wrong
echo %2%\%2%.csproj
dotnet sln add %2%\%2%.csproj
So if I run the above code with input 'some directory' testProject, I would expect the first and second echo to be testProject\testProject.csproj and it is testProject.csproj. What am I doing wrong in the string concatenation?
Example Run of program: CMD: ProjectCreation.bat D:\repos\ProjectSetup\Test TestApp
Terminal Output:
D:\repos\ProjectSetup>echo D:\repos\ProjectSetup\Test
D:\repos\ProjectSetup\Test
D:\repos\ProjectSetup>md D:\repos\ProjectSetup\Test
D:\repos\ProjectSetup>cd D:\repos\ProjectSetup\Test
D:\repos\ProjectSetup\Test>echo TestApp
TestApp ::Output of %2
D:\repos\ProjectSetup\Test>md src
D:\repos\ProjectSetup\Test>md documentation
D:\repos\ProjectSetup\Test>md "documentation/SystemDocuments"
D:\repos\ProjectSetup\Test>md "documentation/Diagrams"
D:\repos\ProjectSetup\Test>cd src
D:\repos\ProjectSetup\Test\src>dotnet new sln --name TestApp
The template "Solution File" was created successfully.
D:\repos\ProjectSetup\Test\src>dotnet new console -o TestApp
The template "Console App" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on D:\repos\ProjectSetup\Test\src\TestApp\TestApp.csproj...
Determining projects to restore...
Restored D:\repos\ProjectSetup\Test\src\TestApp\TestApp.csproj (in 111 ms).
Restore succeeded.
D:\repos\ProjectSetup\Test\src>set "test=TestApp2.csproj"
D:\repos\ProjectSetup\Test\src>echo TestApp2.csproj
TestApp2.csproj
D:\repos\ProjectSetup\Test\src>echo TestApp2.csproj
TestApp2.csproj
D:\repos\ProjectSetup\Test\src>dotnet sln add TestApp2.csproj
Could not find project or directory `TestApp2.csproj`.
Description:
Add one or more projects to a solution file.
Usage:
dotnet [options] sln <SLN_FILE> add [<PROJECT_PATH>...]
Arguments:
<SLN_FILE> The solution file to operate on. If not specified, the command will search the current directory for one. [default: D:\repos\ProjectSetup\Test\src\]
<PROJECT_PATH> The paths to the projects to add to the solution.
Options:
--in-root Place project in root of the solution, rather than creating a solution folder.
-s, --solution-folder <solution-folder> The destination solution folder path to add the projects to.
-?, -h, --help Show command line help.
.bat
file? Add at the beginningecho %2
, and show us the entire output generated by the call in the Command Prompt.