我正在尝试以编程方式将导入任务添加到.csproj文件,但我不想使用Microsoft.Build.BuildEngine对象来执行此操作,因为VS将弹出有关正在修改的项目文件的警告视觉工作室.
我已经看过几页[1] [2]建议IVsBuildPropertyStorage接口让我访问.csproj文件的MSBuild部分,但是我无法弄清楚如何做到这一点,或者它是否真的可能真的.看起来我需要指定我想要访问的属性的名称,但我不知道如何解决这个问题.为"导入"属性调用GetPropertyValue()不会返回已设置的项目文件的任何内容,我希望最终结果如何显示:
EnvDTE.Project proj = ...;
var sol = Package.GetGlobalService(typeof(VsSolution)) as IVsSolution;
IVsHierarchy hier;
sol.GetProjectOfUniqueName(p.UniqueName, out hier);
var storage = hier as IVsBuildPropertyStorage;
string val;
storage.GetPropertyValue("Import", String.Empty,
(uint)_PersistStorageType.PST_PROJECT_FILE, out val);
// val is null
Run Code Online (Sandbox Code Playgroud)
[1] https://mpfproj.svn.codeplex.com/svn/9.0/Tests/UnitTests/ProjectTest.cs
[2] http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/e1983591-120a-4a2f-A910-e596dd625e68
谢谢.我很感激我能得到的任何建议.
我试图使用WriteCodeFragment MSBuild任务创建AssemblyVersion属性。我在创建属性组以正确传递处理所需的ITaskItem数组时遇到问题。有人可以帮忙一个例子。
msbuild msbuild-task msbuild-propertygroup visual-studio msbuild-4.0
在自动化ClickOnce发布过程中,我们使用Mage生成应用程序清单和MsBuild GenerateDeploymentManifest任务.
<GenerateDeploymentManifest AssemblyName="App.exe.application"
AssemblyVersion="$(AppVersion)"
Product="Application"
Install="true"
UpdateEnabled="true"
UpdateMode="Foreground"
OutputManifest="$(PrepareFolder)\App.exe.application"
MapFileExtensions="true"
EntryPoint="@(RelativeApplicationManifestFile)"
CreateDesktopShortcut="true"
MinimumRequiredVersion="$(AppVersion)"
/>
Run Code Online (Sandbox Code Playgroud)
但CreateDesktopShortcut无效,并且不会在部署清单文件中创建所需的标记.
得到这个:
<deployment install="true"
mapFileExtensions="true"
minimumRequiredVersion="2.19.13.0">
Run Code Online (Sandbox Code Playgroud)
代替
<deployment install="true"
mapFileExtensions="true"
minimumRequiredVersion="2.19.13.0"
co.v1:createDesktopShortcut="true">
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我正在进入MSBuild来处理项目的各种目标,我发现它非常灵活.(它也帮助我了解CI系统的可能性)
我需要获得项目的当前SVN修订版本,为此我编写了一个调用SubWCRev并解析输出的自定义任务.
我使用元素引用它:
<UsingTask TaskName="xxx.Elements.Build.MSBuildTasks.SubWCRev" AssemblyFile="D:\dev\xxx_presentation\Build\xxx.Elements.Build.dll">
<ParameterGroup>
<LastCommittedRevision ParameterType="System.Int" Required="False" Output="True" />
<MixedRevisionRangeMinimum ParameterType="System.Int" Required="False" Output="True" />
<MixedRevisionRangeMaximum ParameterType="System.Int" Required="False" Output="True" />
<HasLocalModifications ParameterType="System.Boolean" Required="False" Output="True" />
</ParameterGroup>
</UsingTask>
Run Code Online (Sandbox Code Playgroud)
然后我执行任务......
<Target Name="Version" BeforeTargets="BuildDatabase">
<xxx.Elements.Build.MSBuildTasks.SubWCRev WorkingCopyDir="$(ProjectDir)..">
<Output TaskParameter="LastCommittedRevision" ItemName="LastCommittedRevision" />
<Output TaskParameter="MixedRevisionRangeMinimum" ItemName="MixedRevisionRangeMinimum" />
<Output TaskParameter="MixedRevisionRangeMaximum" ItemName="MixedRevisionRangeMaximum" />
<Output TaskParameter="HasLocalModifications" ItemName="HasLocalModifications" />
</xxx.Elements.Build.MSBuildTasks.SubWCRev>
<Message Text="Revision is @(LastCommittedRevision)" />
</Target>
Run Code Online (Sandbox Code Playgroud)
我的问题是MSBuild坚持使用TaskFactory属性,本文档说这是可选的.而且我也看到TaskFactory特别适用于内联任务,我对此并不感兴趣.
错误消息是:
必需属性"TaskFactory"在元素UsingTask中为空或缺少.
我哪里错了?
(顺便说一句,我发现MSBuild Sidekick 3非常出色并且减少了可能成为一个相当复杂的脚本的阻力.)
我正在使用以下命令通过 MSBuild 文件安装服务。这很好用
<Exec Command= 'c:\test\myService.Appservices.exe install' ContinueOnError='false' />
Run Code Online (Sandbox Code Playgroud)
但是上面的命令在本地计算机上安装了服务。我想在远程计算机上安装该服务。如何使用此命令指定机器名称?
假设我在一个属性中得到了这个AB_1.2.3.112211
我想要的是交换第一个"." 到一个"_"
因此它变为AB_1_2.3.112211两个第一个字符可能更长fx ABCD_1.2.3.112211但它仍然应该是输出ABCD_1_2.3.112211
有没有办法在msbuild任务中执行此操作?
如何确定是否在MSBuild .targets文件中以调试(或发布)模式构建项目,并将此信息用作另一个属性的条件?
就像是:
<OutDir Condition="IsDebug">bin\Debug\$(SomeOtherProperty)\</OutDir>
<OutDir Condition="!IsDebug">bin\Release\$(SomeOtherProperty)\</OutDir>
Run Code Online (Sandbox Code Playgroud)
是否有诸如“调试/发布”模式之类的东西,或者它们仅仅是不同配置属性值集的常规名称?
我想在我的 SSDT 项目中有条件地构建部署后脚本,但我不明白该怎么做。因此,通常会构建部署后脚本,但我想要一种在进行调试构建时不构建或运行部署后脚本的方法。我正在从命令行运行构建,因此我可以传入属性,但是如何使用属性来不运行部署后脚本?
我看到的选项是 SQLCMD,或编辑 SQLPROJ 文件,或传入属性,但我找不到任何关于 SQLPROJ 文件可用属性和不可用属性的参考。
我想要有条件构建的文件位于此处:
<ItemGroup>
<PostDeploy Include="PostDeploymentScripts\Script.PostDeployment1.sql" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
我的调试构建块如下所示:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我的命令行如下所示:
msbuild $sqlprojFilePath /p:Configuration="Debug"
Run Code Online (Sandbox Code Playgroud) 我有一个.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 "& { $(ScriptLocation) } "" />
</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) 在 Azure DevOps 中,是否可以在构建任务期间导出在 MSBuild 任务中定义的少数 MSBuild 属性,并将这些属性用作构建作业中其他任务的变量?
用例:构建期间计算的版本号
我们创建了一个 MSBuild 任务,作为构建的一部分,从 git 标签确定版本号。MSBuild 任务使用它来设置程序集版本以及作为构建的一部分打包的可能的 nuget 包。
现在,在设置 Azure DevOps 构建管道时,我有一个单独的步骤来构建服务的安装程序(使用高级安装程序的 .msi)。我需要在 MSBuild 任务期间确定版本并将其传递给 Advanced Installer 构建任务,因此可以对其进行相应的版本控制。如何做到这一点?
作为一种解决方法,我们之前一直使用单独的构建任务,其中版本已使用 bash 脚本确定。然后导出到 VSO 变量并传递给MSBuild和Advanced Installer build两个任务(MSBuild 任务可以使用预定义的属性作为版本值)。现在我想摆脱计算版本的重复方式。
Azure Pipeline 项目有两个构建代理
构建成功,资产、chunk.js 文件和bundle.js 文件作为工件发布
我从以前的构建代理下载工件并将它们提取到$(build.stagingDirectory)/Scripts/dist目录中,因为它们将被 ASP.net 项目使用。
我的提取文件任务 ymal 是
steps:
- task: ExtractFiles@1
displayName: 'Extract files bundle.zip'
inputs:
archiveFilePatterns: '$(Pipeline.Workspace)/dist/$(Build.BuildId)_bundle.zip'
destinationFolder: '$(build.sourcesDirectory)/Scripts/dist'
Run Code Online (Sandbox Code Playgroud)
当MSBuild构建 ASP.net 项目时,它无法找到##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets(182,5): Error MSB3030: Could not copy the file "Scripts\dist\main.bundle.js" because it was not found.
MS Build yaml 是:
steps:
- task: MSBuild@1
displayName: 'Build solution NMG.Portal.MVCForAngular'
inputs:
solution: NMG.WebApp.MVCForAngular/NMG.WebApp.MVCForAngular.csproj
msbuildArguments: '/p:ProjectFile=$(build.sourcesDirectory)\NMG.WebApp.MVCForAngular\NMG.WebApp.MVCForAngular.csproj /p:DeployOnBuild=true /p:SkipInvalidConfigurations=true /p:OutDir="$(build.stagingDirectory)\\"'
clean: false
logProjectEvents: …Run Code Online (Sandbox Code Playgroud) msbuild asp.net-mvc msbuild-task angular-cli azure-pipelines
我正在尝试将MSBuild.ExtensionPack.Web.Iis7AppPool任务与 GetInfo 任务操作一起使用。该任务的输出参数是SiteInfo属性,其类型是ITaskItem。这是财产,而不是收藏。
如何访问 SiteInfo 元数据?我可以用 $ 访问,但我只能得到网站名称。我尝试使用 %(SiteInfo.) 但没有成功。
msbuild ×12
msbuild-task ×12
msbuild-4.0 ×3
.net ×1
angular-cli ×1
asp.net ×1
asp.net-mvc ×1
azure-devops ×1
clickonce ×1
csproj ×1
execcommand ×1
itaskitem ×1
powershell ×1
sqlproj ×1
targets ×1