简体   繁体   English

核心 ASP.NET 项目 Azure 构建管道

[英]Core ASP.NET Project Azure Build Pipeline

I have a simple solution that have two projects in it and I want it go through the azure build pipeline.我有一个简单的解决方案,其中有两个项目,我希望它通过 azure 构建管道实现 go。 One project is pure class files that will get build a DLL but that code is not the GIT repo in the same folder.一个项目是纯 class 文件,它将构建一个 DLL 但该代码不是同一文件夹中的 GIT 存储库。 And the other project is ASP.NET project and I have configured that in the pipeline.另一个项目是 ASP.NET 项目,我已经在管道中进行了配置。 When I am trying to build the project it is giving me an error as below:当我尝试构建项目时,它给了我一个错误,如下所示:

MSBUILD: error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file. MSBUILD:错误 MSB1011:指定要使用的项目或解决方案文件,因为此文件夹包含多个项目或解决方案文件。 [error]Cmd.exe exited with code '1'. [错误] Cmd.exe 以代码“1”退出。

Yaml File Yaml文件

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  name: 'buildserver'

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

The error is asking you to identify the .sln or .csproj (or other proj type) file b/c dotnet doesn't know what you want it to do.该错误要求您识别.sln.csproj (或其他 proj 类型)文件 b/c dotnet不知道您想要它做什么。

I tend to use variables for this kind of thing because I'm often using the solution name in other tasks.我倾向于将变量用于此类事情,因为我经常在其他任务中使用解决方案名称。

example:例子:

trigger:
- master

pool:
  name: 'buildserver'

variables:
  buildConfiguration: 'Release'
  slnName: 'mySol'
  solution: 'some/dir/$(slnName).sln'

steps:
- script: dotnet build $(solution) --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

.csproj example: .csproj 示例:

With a repository (and solution) structure as follows:具有如下存储库(和解决方案)结构:
(this is the part of your question that remains unclear) (这是您问题中尚不清楚的部分)

myRepo
|--.git
|--src
   |--proj1
   |  |--proj1.csproj
   |
   |--proj2
   |  |--proj2.csproj
   |
   |--mySol.sln

You would simply call out the .csproj file you want the pipeline to build.您只需调用要构建管道的.csproj文件。

trigger:
- master

pool:
  name: 'buildserver'

variables:
  buildConfiguration: 'Release'
  projName: 'proj1'
  project: 'src/$(projName)/$(projName).csproj'

steps:
- script: dotnet build $(project) --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

With the above examples you shouldn't need to specify the .sln or .csproj as each potential build target lives in its own directory, and the dotnet cli searches from $pwd if you don't give it a value.对于上面的示例,您不需要指定.sln.csproj ,因为每个潜在的构建目标都位于其自己的目录中,如果您不给它一个值,dotnet cli 将从$pwd搜索。 Therefore, if your pipeline is working in the root of the repo (default behavior), dotnet should find the .sln file first and build it.因此,如果您的管道在 repo 的根目录中工作(默认行为), dotnet应该首先找到.sln文件并构建它。

However然而

If your directory structure looks like the following, then you would need to specify:如果您的目录结构如下所示,则需要指定:

myRepo
|--.git
|--src
   |--proj1.csproj
   |--class1.cs
   |--class2.cs
   |--proj2
   |  |--proj2.csproj
   |  |--class1.cs
   |
   |--mySol.sln

In the above dotnet doesn't know whether you want to build mySol.sln or proj1.csproj , so indicating the file to build should solve your problem, but I might suggest that you restructure your repository.在上面的dotnet中不知道您是要构建mySol.sln还是proj1.csproj ,因此指示要构建的文件应该可以解决您的问题,但我可能会建议您重组存储库。

If proj2 doesn't make its home in myRepo如果proj2不在myRepo中安家

And is a dependency of proj1 then you will need to do some other acrobatics (ie: manual git repo clone) in the pipeline to get that project and it's files where they need to be.并且是proj1的依赖项,那么您将需要在管道中执行一些其他杂技(即:手动 git 回购克隆)以获取该项目及其需要的文件。 If this is the case, I would strongly suggest you treat proj2 as a completely independent product and deliver it to those projects ( proj1 ) that depend upon it via NuGet or other package delivery method.如果是这种情况,我强烈建议您将proj2视为完全独立的产品,并通过 NuGet 或其他 package 交付方法将其交付给依赖它的项目( proj1 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM