简体   繁体   English

.Net Core Visual Studio 项目命令行构建与右键构建相同

[英].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.

相关问题 通过命令行构建 Visual Studio 项目 - Build Visual Studio project through the command line 从命令行在2017 Visual Studio中构建项目? - Build project in 2017 Visual Studio from the command line? 如何使用命令行构建 Visual Studio 安装项目? - How to build Visual studio Setup project using command-line? 项目不是在活动配置Visual Studio MacOS .net Core中构建的 - Project not build in active configuration Visual Studio MacOS .net Core 命令行生成解决方案与Visual Studio 2012生成 - Command line build solution vs Visual Studio 2012 build 新的.net核心视觉工作室2017项目nuget恢复CI构建定义 - new .net core visual studio 2017 project nuget restore in CI build definition Visual Studio不会构建它创建的ASP.NET Core项目 - Visual Studio won't build the ASP.NET Core project it created 如何使用 BuildManager 在 Visual Studio 2017 (MsBuild 15) 上构建 .Net Core 项目或解决方案 - How to use BuildManager to build .Net Core project or solution on Visual Studio 2017 (MsBuild 15) Visual Studio 2017 Asp.Net Core 项目不会在构建时复制依赖的 dll 文件 - Visual Studio 2017 Asp.Net Core project doesn't copy dependent dll file on build 如何自动化(从命令行)安装 Visual Studio Build Tools 构建环境,适用于 C++、.NET、C# 等 - How to automate (from command-line) the installation of a Visual Studio Build Tools build environment, for C++, .NET, C#, etc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM