[英].Net Core Visual Studio project command line build same as right-clicking build
I would like to be able to run a batch command to build my C# .NET Core project the exact same way that it builds when I right click the project in the solution and select build in Visual Studio.我希望能够运行批处理命令来构建我的 C# .NET Core 项目,其方式与我右键单击解决方案中的项目并选择在 Visual Studio 中构建时的构建方式完全相同。
I have tried the following我已经尝试了以下
dotnet build
dotnet build --configuration Debug
dotnet build --no-restore
dotnet build --no-dependencies
and a mixture of the above, none of them seem to build the project in the same way that right-clicking on the project and selecting build does.以及上述的混合,它们似乎都没有以与右键单击项目并选择构建相同的方式构建项目。 Can someone point me in the direction or does anyone know the commands to run to build the exact same way that right-clicking the project builds?
有人可以指出我的方向,或者有人知道运行的命令以与右键单击项目构建的方式完全相同吗?
So the main issue that I faced here was that I was trying to build a WPF with the dotnet command line tool.所以我在这里面临的主要问题是我试图用 dotnet 命令行工具构建一个 WPF。 In order to keep the same configuration build as my solution I had to run msbuild directly instead of using dotnet below is the code that I used to solve this problem
为了保持与我的解决方案相同的配置构建,我必须直接运行msbuild而不是使用dotnet下面是我用来解决这个问题的代码
SET SolutionPath=%1
@ECHO OFF
CLS
ECHO ------------------------------------------------------------
ECHO Building WPF UI Project
ECHO ------------------------------------------------------------
cd %SolutionPath%
msbuild MySolution.sln -t:MySolution_WPF_UI -p:Configuration=Debug -p:Platform="x64" -p:WarningLevel=0 -
v:minimal
if %ERRORLEVEL% GEQ 1 (
ECHO ------------------------------------------------------------
ECHO ****** THIS PROJECT HAD ERRORS DURING BUILD *******
ECHO ------------------------------------------------------------
pause
)
TIMEOUT 4
EXIT
NOTE: if your project contains "."注意:如果您的项目包含“.” periods in the project name then they must be substituted with "_" underscores.
项目名称中的句点,则它们必须替换为“_”下划线。 In the above example the projects name is "MySolution.WPF.UI" but has been passed as in input parameter as "MySolution_WPF_UI" ALSO be aware that visual studio will save all files in your project prior to a build so before you build with a script like this you should use
在上面的例子中,项目名称为“MySolution.WPF.UI”但作为输入参数已通过的“MySolution_WPF_UI”另外要注意,Visual Studio将之前保存的所有文件在您的项目,以构建你建立一个如此前你应该使用这样的脚本
CTRL + SHIFT + S
to save your projects, otherwise if you have recently added or removed files from your project they may not be referenced in the build.保存您的项目,否则如果您最近从项目中添加或删除了文件,则它们可能不会在构建中引用。 Also note you must have msbuild in your environmental PATH variables for this to work
另请注意,您的环境 PATH 变量中必须有 msbuild 才能正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.