Azure项目构建包在VS中工作,从命令行失败,错误MSB4096
本文关键字:命令行 失败 MSB4096 错误 工作 构建 项目 VS Azure | 更新日期: 2023-09-27 18:18:05
我有一个Windows Azure云服务项目的解决方案,从VS和命令行编译得很好。
如果我尝试制作一个包,它在VS中工作得很好,但在命令行中失败。
下面是我在Powershell中的命令行:
C:'Windows'Microsoft.NET'Framework'v4.0.30319'MSBuild.exe .'project.sln --%
/p:Configuration="QA" /p:TargetProfile="CloudQA" /p:Platform="Any CPU" /target:Publish
/nr:false
我有这个错误:
"C:'CI'project'project.sln" (Publish target) (1) ->
"C:'CI'project'WindowsAzure'WindowsAzure.ccproj.metaproj" (Publish target) (11) ->
"C:'CI'project'WindowsAzure'WindowsAzure.ccproj" (Publish target) (12) ->
(PrepareRoleItems target) ->
C:'Program Files (x86)'MSBuild'Microsoft'VisualStudio'v11.0'Windows Azure Tools'2.0'Microsoft.WindowsAzure.targets(13
02,5): error MSB4096: The item "C:'CI'project'project.WebAPI'project.WebAPI.csproj" in item list "Projec
tReferenceWithConfiguration" does not define a value for metadata "Name". In order to use this metadata, either qualif
y it by specifying %(ProjectReferenceWithConfiguration.Name), or ensure that all items in this list define a value for
this metadata. [C:'CI'project'WindowsAzure'WindowsAzure.ccproj]
编辑一些有趣的事情:这是我的csdef文件
<WorkerRole name="ProjectWorker" vmsize="ExtraSmall">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InternalEndpoint name="InternalEndpoint1" protocol="http" />
</Endpoints>
<ConfigurationSettings>
</ConfigurationSettings>
</WorkerRole>
<WebRole name="Project.Web" vmsize="ExtraSmall">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="http" endpointName="http" />
</Bindings>
</Site>
<Site name="Api" physicalDirectory="..'..'..'Project.WebAPI">
<Bindings>
<Binding name="http" endpointName="http81" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="http" protocol="http" port="80" />
<InputEndpoint name="http81" protocol="http" port="81" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WebRole>
正如你所看到的,我在一个WebRole上有两个网站。
现在,让我们看一下ccproj文件:
<ItemGroup>
<ProjectReference Include="..'Project.Web'Project.Web.csproj">
<Name>Project.Web</Name>
<Project>{5d000123-0000-4b6e-b5fa-72525afca7f5}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.Web</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
<ProjectReference Include="..'ProjectWorker'ProjectWorker.csproj">
<Name>ProjectWorker</Name>
<Project>{22e99999-1000-4559-8507-a948b7e3d1b0}</Project>
<Private>True</Private>
<RoleType>Worker</RoleType>
<RoleName>ProjectWorker</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
</ItemGroup>
在ccproj中只引用了两个项目,而不是3个。
云项目在sln中有3个依赖项。
如果我在ccproj中有一个像这样的手工引用:
<ProjectReference Include="..'Project.WebAPI'Project.WebAPI.csproj">
<Name>Project.Web</Name>
<Project>{A0F88888-3333-4823-A34F-5F01F0A3FFFF}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.WebAPI</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
我有这个错误:
C:'Program Files (x86)'MSBuild'Microsoft'VisualStudio'v11.0'Windows Azure Tools'2.0
'Microsoft.WindowsAzure.targets(987,5): error : CloudServices25 : Multiple directories are
specified for role Project.Web. [C:'CI'project'WindowsAzure'WindowsAzure.ccproj]
如果我像这样更新引用:
<ProjectReference Include="..'Project.WebAPI'Project.WebAPI.csproj">
<Name>Project.WebAPI</Name>
<Project>{A0F88888-3333-4823-A34F-5F01F0A3FFFF}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.Web</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
我有这个错误:
C:'Program Files (x86)'MSBuild'Microsoft'VisualStudio'v11.0'Windows Azure Tools'2.0
'Microsoft.WindowsAzure.targets(987,5): error : CloudServices26 : Cannot find role
named 'Project.WebAPI' in service description file
C:'CI'project'WindowsAzure'bin'UAT'ServiceDefinition.csdef.
[C:'CI'project'WindowsAzure'WindowsAzure.ccproj]
我发现了这个链接:Visual Studio 2010 Beta 2 myTODO错误消息它为我工作。链接中有价值的信息:
如果你指定Azure角色项目之外的任何东西作为服务项目的依赖项,Azure似乎不喜欢它。我把它做成了MyWebRole。Csproj依赖于xxx。csproj,而不是MyService。Ccproj依赖于xxx。
这篇文章解决了我的问题:http://michaelcollier.wordpress.com/2013/01/14/multiple-sites-in-a-web-role/
如果你在一个网页上有几个网站,一定要读!
我在从命令行构建我的云项目时偶然发现了一个类似的问题,特别是如果VirtualDirectory
标记引用的web项目被标记为云项目的构建依赖,我会得到这个异常。
为了避免这种情况,并确保web项目被编译并包含在cspack
中,我提出了一个比Swell回答中引用的更简单的过程——特别是它不需要更改项目文件,而只需要以精确的顺序调用两个目标:
- 确保在
Configuration Manager
中web项目将在所需的解决方案配置中重建(例如确保它在Release
配置下构建); - 确保web项目不是云项目的构建依赖;
-
重新构建解决方案,例如
MsBuild solution.sln /t:Rebuild ...
-
执行云项目的发布,例如
MsBuild solution.sln /t:cloudproject.ccproj:publish ...
web项目将被正确复制到
cspack
文件