小编mck*_*dev的帖子

无法命令行构建混合解决方案(.NET Framework与.NET标准)

简短版本:我有一个VS2017解决方案,包含2个.NET Standard 2.0项目,一个.NET Framework 4.6.2类库和.NET Framework 4.6.2 MVC WebApp.什么是正确的命令行构建实用程序来恢复所有nuget包,然后在解决方案中构建所有项目?

长版本:我已将针对.NET Framework 4.5和Visual Studio Pro 2015的解决方案迁移到Visual Studio Pro 2017,其中一些项目针对.NET Framework 4.6.2,一些针对.NET Standard 2.0.根据https://github.com/dotnet/standard/blob/master/docs/versions.md,这个特定版本的Framework/Standard组合应该是兼容的.

这是我今天的解决方案:

WebApp - 面向.NET Framework 4.6.2的MVC 5.0 ASP.NET Web应用程序项目.这是一个最初在Visual Studio 2013中创建的MVC Web应用程序,并且已经多次升级以跟上.NET Framework升级.

ModelsLibrary - .NET Standard 2.0,同时针对Standard和4.6.2*.除了在整个解决方案中使用的普通C对象外,只包含其他内容.

LogicLibrary - .NET Standard 2.0,同时针对Standard和4.6.2*.包含对我们的POCO进行更改和/或使用来自POCO的数据调用第三方服务的业务逻辑.

ServiceLibrary - .NET Framework 4.6.2类库项目.执行WebApp的CRUD操作.从数据库中提取,插入或更新的所有对象都是ModelsLibrary项目中的POCO.无法更新到.NET Standard,因为我们在整个项目中都非常依赖linq to SQL,并且在.NET Standard中没有实现linq to SQL.

TestsProject - 使用Microsoft.VisualStudio.QualityTools.UnitTestFramework的.NET Framework 4.6.2单元测试项目.对整个解决方案中执行的少量关键逻辑操作执行基本单元测试.如果是问题,可以删除该项目,并且新的测试项目可以及时替换它.

*ModelsLibrary和LogicLibrary项目的CSProj文件包含以下行:

<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)'=='net'">.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)'=='netstandard'">.NETStandard</TargetFrameworkIdentifier>
Run Code Online (Sandbox Code Playgroud)

该解决方案具有以下参考:

WebApp引用了LogicLibrary,ModelsLibrary,ServiceLibrary

LogicLibrary对ModelsLibrary具有项目依赖性

ModelsLibrary没有项目依赖性

ServiceLibrary引用ModelsLibrary …

.net msbuild teamcity .net-standard

6
推荐指数
1
解决办法
3206
查看次数

在MSBuild期间运行Powershell脚本

我有一个.NET Framework 4.5.2 WebAPI2项目。在Visual Studio中构建项目时,我希望在每次构建之前都运行我编写的Powershell脚本。如果powershell脚本以任何非零代码退出,则我希望构建失败,并且来自powershell脚本的错误消息在Visual Studio输出中可见。

到目前为止,这是我修改csproj文件的方式:

<Project ToolsVersion="12.0" DefaultTargets="MyCustomTarget;Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<Target Name="MyCustomTarget">
  <PropertyGroup>
    <PowerShellExe Condition=" '$(PowerShellExe)'=='' "> 
      %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    </PowerShellExe>
    <ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
      C:\Code\MyScript.ps1
    </ScriptLocation>
  </PropertyGroup>
  <Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { $(ScriptLocation) } &quot;" />
</Target>
Run Code Online (Sandbox Code Playgroud)

为了简单起见,我的脚本如下:

if(((get-date -Format "mm") % 2) -eq 0){ exit 0 } else { write-error "The minute is not equally divisible by 2.";exit 1 }
Run Code Online (Sandbox Code Playgroud)

但是,当我去构建项目时,我现在看到我的Powershell脚本在记事本中打开,并且构建停止,直到我关闭记事本。关闭后,我遇到了错误,但找不到任何解决错误的方法。任何帮助将不胜感激。

The command " 
    %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
   -NonInteractive -executionpolicy Unrestricted -command "& { 
    C:\Code\MyScript.ps1
   } "" exited …
Run Code Online (Sandbox Code Playgroud)

asp.net msbuild powershell csproj msbuild-task

1
推荐指数
1
解决办法
2405
查看次数