简体   繁体   English

在MsBuild文件中包含.sln文件?

[英]Include .sln file in MsBuild file?

I'm trying to build Visual Studio project from .msbuild file. 我正在尝试从.msbuild文件构建Visual Studio项目。 The idea is to do some things before the build, then execute build of .sln from the same place. 这个想法是在构建之前做一些事情,然后从同一位置执行.sln构建。

Something like this: 像这样:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="BuildClient" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <Tools>$(MSBuildProjectDirectory)\tools</Tools>
    <NugetExe>$(Tools)\nuget\nuget.exe</NugetExe>
    <ClientFolder>$(MSBuildProjectDirectory)\src\Client</ClientFolder>
    <ClientSolution>$(ClientFolder)\ClientProject.sln</ClientSolution>
  </PropertyGroup>

  <Target Name="BuildClient">
    <!--Restore Nuget-->
    <Message Text="Starting Restoring Nuget Packages" />
    <Exec Command=" $(NugetExe) restore $(ClientSolution)" />
    <Message Text="Finished Restoring Nuget Packages" />


    <Import Project="$(ClientSolution)" />

    <!--build project-->
  </Target>
</Project>

But line with <Import> is underlined in VS, saying import should be on level up, not within <Target> . 但是在VS中带<Import>行带有下划线,表示导入应该在级别上,而不是在<Target> When I move <Import> a level up as suggested I get an execution error: 当我按照建议将<Import>移时,出现执行错误:

errorMSB4025: The project file could not be loaded. Data at the root level is invalid.

Any idea how to build whole project without major rewriting? 知道如何在不进行重大重写的情况下构建整个项目吗?

Silly me! 傻我! the solution turns out to be very simple: 该解决方案非常简单:

<MSBuild Projects="..\..\MySolution.sln" "/>

This did the trick with executing the build on .sln file 这可以在.sln文件上执行构建而达到目的

I got the pointer from this answer . 我从这个答案中得到了指示。

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

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