프로젝트 디렉터리를 만든 다음 dotnet 프로젝트를 만드는 bat 스크립트를 작성 중입니다. 스크립트에서는 csproj 파일을 참조하여 액세스하려고 합니다. 내가 겪고 있는 문제는 디렉터리 이름을 가져오지 않는다는 것입니다. 내 bat 스크립트는 프로젝트 디렉터리와 프로젝트 이름이라는 두 가지 입력을 사용합니다.
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
따라서 '일부 디렉터리' testProject를 입력하여 위 코드를 실행하면 첫 번째와 두 번째 에코가 testProject\testProject.csproj이고 testProject.csproj가 될 것으로 예상됩니다. 문자열 연결에서 내가 뭘 잘못하고 있는 걸까요?
예 프로그램 실행: CMD: ProjectCreation.bat D:\repos\ProjectSetup\Test TestApp
터미널 출력:
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.
답변1
문제는 다음 명령입니다.
set "test=%2\%2.csproj"
문제 %2%
는 %2
.