[英]dotnet publish only one project from the solution in VSTS
We are trying to build one project from a Visual Studio solution in VSTS with .NET Core task.我们正在尝试使用.NET Core任务从 VSTS 中的 Visual Studio 解决方案构建一个项目。 We are able to "dotnet build" that project.
我们能够“dotnet 构建”该项目。 But when we try to "dotnet publish" it tries to publish all projects from the solution.
但是当我们尝试“dotnet 发布”时,它会尝试发布解决方案中的所有项目。 Even if we use "dotnet custom", it tries to publish all projects.
即使我们使用“dotnet custom”,它也会尝试发布所有项目。
Is there a way to use .NET Core task to publish only one project or projects that were built?有没有办法使用 .NET Core 任务只发布一个或多个已构建的项目? Or should we run a custom command line task?
或者我们应该运行一个自定义的命令行任务?
Reason for this is that we have a project that won't build and we don't need/want to publish it.这样做的原因是我们有一个无法构建的项目,我们不需要/不想发布它。 So we would like to build and publish one project and not all projects.
所以我们想构建和发布一个项目,而不是所有项目。
You can use dotnet publish <Path to .csproj>
.您可以使用
dotnet publish <Path to .csproj>
。 This will build and publish only the specified project and projects it depends on.这将仅构建和发布指定的项目和它所依赖的项目。
In order to specify a project in the '.Net Core' task with the command 'publish' you have to uncheck 'Publish Web Projects'.要使用命令“发布”在“.Net Core”任务中指定项目,您必须取消选中“发布 Web 项目”。
Another solution would be to set IsPublishable
in csproj.另一种解决方案是在
IsPublishable
中设置 IsPublishable。
I usually do it in cases where it's a unit test project or else that doesn't need to be published if you run dotnet publish
for solution file.我通常在它是单元测试项目的情况下这样做,或者如果您为解决方案文件运行
dotnet publish
则不需要dotnet publish
。
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable >
<Configurations>prod;stage;dev</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
This is decided on Project Dependencies for each projects.这是由每个项目的项目依赖关系决定的。
In other words, there are some configuration to say that "which project need to build first, in order to let your target project successfully build."也就是说,有一些配置说“需要先构建哪个项目,才能让你的目标项目成功构建”。
If you are using Visual Studio, right click on solution and click 'Properties'.如果您使用的是 Visual Studio,请右键单击解决方案并单击“属性”。 In this example, my target run is
TestAngular.Web.Host
and in order to build that projects, it's required to build TestAngular.Web.Core
first.在此示例中,我的目标运行是
TestAngular.Web.Host
,为了构建该项目,需要先构建TestAngular.Web.Core
。
If you are using different IDE, simply locate to your directory, in my case it would be src\\TestAngular.Web.Host
and modify TestAngular.Web.Host.csproj
file如果您使用不同的 IDE,只需找到您的目录,在我的情况下它将是
src\\TestAngular.Web.Host
并修改TestAngular.Web.Host.csproj
文件
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<ItemGroup>
<ProjectReference Include="..\TestAngular.Web.Core\TestAngular.Web.Core.csproj" />
</ItemGroup>
...
</Project Sdk="Microsoft.NET.Sdk.Web">
Add or remove which projects are not required here following same syntax按照相同的语法添加或删除此处不需要的项目
Maybe late to the party but in order to have control over what projects to publish, you could unlink the "Path to project(s)" variable (by clicking on "Link settings").也许迟到了,但为了控制要发布的项目,您可以取消链接“项目路径”变量(通过单击“链接设置”)。 That makes the field editable and you can specify your desired .csproj.
这使得该字段可编辑,您可以指定所需的 .csproj。
Sorry, that I am late to the party, but the solution is much more simple, uncheck Publish Web Projects
in the publish task in DevOps:抱歉,我迟到了,但解决方案要简单得多,在 DevOps 的发布任务中取消选中
Publish Web Projects
:
Publish Web Projects: If true, the projects property value will be skipped and the task will try to find the web projects in the repository and run the publish command on them.发布 Web 项目:如果为 true,项目属性值将被跳过,任务将尝试在存储库中查找 Web 项目并对它们运行发布命令。 Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.
Web 项目通过目录中是否存在 web.config 文件或 wwwroot 文件夹来标识。 In the absence of a web.config file or wwwroot folder, projects that use a web SDK, like Microsoft.NET.Sdk.Web, are selected.
如果没有 web.config 文件或 wwwroot 文件夹,则会选择使用 Web SDK(如 Microsoft.NET.Sdk.Web)的项目。 Note that this argument defaults to true if not specified.
请注意,如果未指定,则此参数默认为 true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.