即使我的目标是.NET Framework(3.5)的相同版本,我的项目还是使用MSBuild 4构建的,而不是使用MSBuild 3.5构建的? [英] My project builds with MSBuild 4 but not with MSBuild 3.5 even though I'm targeting the same version of the .NET Framework (3.5)?

查看:206
本文介绍了即使我的目标是.NET Framework(3.5)的相同版本,我的项目还是使用MSBuild 4构建的,而不是使用MSBuild 3.5构建的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用MSBuild 4构建解决方案时,它会成功编译:

When I build my solution using MSBuild 4 it compiles successfully:

C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ MSBuild.exe MySolution.sln

构建成功.

Build succeeded.

0 Warning(s)
0 Error(s)

但是当我尝试使用MSBuild 3.5进行相同操作时,即使源相同并且我使用的是相同的库和相同的.NET Framework版本,也会收到以下错误消息.

But when I try to do the same using MSBuild 3.5 I get the following error, even though the source is the same and I am using the same libraries and the same version of the .NET Framework.

C:\ Windows \ Microsoft.NET \ Framework \ v3.5 \ MSBuild.exe MySolution.sln

错误CS1501:方法'InitializeClientContextFromStringSid'的重载没有接受'2'参数

error CS1501: No overload for method 'InitializeClientContextFromStringSid' takes '2' arguments

错误CS1501:方法'GetRoles'的重载没有接受'0'参数

error CS1501: No overload for method 'GetRoles' takes '0' arguments

我得到的错误与授权管理器(AzMan)有关.

The error that I get is related to Authorization Manager (AzMan).

第一个错误中的方法'InitializeClientContextFromStringSid'属于公共接口IAzApplication,它是Microsoft.Interop.Security.AzRoles的成员.

The method 'InitializeClientContextFromStringSid' in the first error belongs to the public interface IAzApplication, a member of Microsoft.Interop.Security.AzRoles.

第二个错误中的方法'GetRoles'属于公共接口IAzClientContext,它也是Microsoft.Interop.Security.AzRoles的成员.

The method 'GetRoles' in the second error belongs to the public interface IAzClientContext, also a member of Microsoft.Interop.Security.AzRoles.

我通过以下方式使用这些方法:

I am using the methods in the following way:

var clientContext = _azApplication.InitializeClientContextFromStringSid(member, 0);

其中变量成员是包含来自用户的Windows Active Directory SID的字符串,而_azApplication的类型为IAzApplication.

where the variable member is a string containing the Windows Active Directory SID from an user and _azApplication is of type IAzApplication.

clientContext.GetRoles()

其中clientContext的类型为IAzClientContext.

where clientContext is of type IAzClientContext.

即使我的目标是.NET Framework(3.5)的同一版本,为什么我的解决方案仍使用MSBuild 4构建而不能使用MSBuild 3.5构建?

推荐答案

看来InitializeClientContextFromStringSid在规范中具有可选参数.尽管.Net Framework 4.0中的MSBuild通过允许您将它们排除在函数调用之外而在C#中支持使用可选参数,但以前版本的MSBuild不支持此方法.因此,即使在使用较早版本的Framework进行构建时,即使未使用该参数,也必须提供该参数.

It looks like InitializeClientContextFromStringSid has an optional parameter in the specification. Though MSBuild in .Net Framework 4.0 supports the use of optional parameters in C# by allowing you to leave them out of the function call, previous versions of the MSBuild do not support this approach. So you must to supply the parameter even if it's not being used when building with older version of the Framework.

HRESULT InitializeClientContextFromStringSid(
  [in]            BSTR SidString,
  [in]            LONG lOptions,
  [in, optional]  VARIANT varReserved,
  [out]           IAzClientContext **ppClientContext
);

GetRoles方法也发生同样的问题.

The same issue is happening with the GetRolesmethod.

据我了解,可以使用4.0版本的MSBuild和目标3.5 Framework进行构建的原因是CLR已经支持使用Optional参数,例如VB.NET一直都支持它们.但是,在使用MSBuild 3.5时,它将使用较旧的规则/规范,该规则/规范不允许在C#中支持Optional参数,因此会给您带来构建错误.

From my understanding, the reason you can build using the 4.0 version of MSBuild and target 3.5 Framework is that the CLR already supported the use of Optional parameters, for example VB.NET has always supported them. However, when using MSBuild 3.5, it is going to use the older rules/specification that did not allow support for Optional parameters in C# and thus will give you build errors.

这篇关于即使我的目标是.NET Framework(3.5)的相同版本,我的项目还是使用MSBuild 4构建的,而不是使用MSBuild 3.5构建的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆