饭饭TXT > 学习管理 > 《Visual Studio 2010 高级编程(英文出书版)》作者:Nick Randolph/等【完结】 > [Visual.Studio.2010.高级编程].Professional.Visual.Studio.2010.txt

第 20 页

作者:Nick Randolph/等 当前章节:15425 字 更新时间:2026-6-18 14:51

C# provide a mechanism for importing namespaces so that classes can be referenced directly. The

References section allows namespaces to be globally imported for all classes in the project, without

them being explicitly imported within the class file.

References to external assemblies can either be File references or Project references. File references

are direct references to an individual assembly. File references are created by using the Browse tab of

the Add Reference dialog box. Project references are references to a project within the solution. All

assemblies that are outputted by that project are dynamically added as references. Project references

are created by using the Project tab of the Add Reference dialog box.

You should generally not add a File reference to a project that exists in the same

solution. If a project requires a reference to another project in that solution, a

Project reference should be used.

The advantage of a Project reference is that it creates a dependency between the projects in the

build system. The dependent project will be built if it has changed since the last time the referencing

project was built. A File reference doesn’t create a build dependency, so it’s possible to build the

referencing project without building the dependent project. However, this can result in problems

with the referencing project expecting a different version from what is included in the output.

resources

Project resources can be added and removed via the Resources tab, shown in Figure 6-14. In the

example shown, four icons have been added to this application. Resources can be images, text,

icons, files, or any other serializable class.

fiGure 6-14

Project Properties .

107

This interface makes working with resource files at design time very easy. Chapter 38 examines

in more detail how resource files can be used to store application constants and internationalize

your application.

services

Client application services allow Windows-based applications to use the authentication, roles,

and profile services that were introduced with Microsoft ASP.NET 2.0. The client services enable

multiple web- and Windows-based applications to centralize user profiles and user-administration

functionality.

Figure 6-15 shows the Services tab, which is used to configure client application services for

Windows applications. When enabling the services, the URL of the ASP.NET service host must be

specified for each service. This will be stored in the app.config file. The following client services

are supported:

.

Authentication: This enables the user’s identity to be verified using either the native

Windows authentication, or a custom forms-based authentication that is provided by the

application.

.

Roles: This obtains the roles an authenticated user has been assigned. This enables you

to allow certain users access to different parts of the application. For example, additional

administrative functions may be made available to admin users.

.

Web Settings: This stores per-user application settings on the server, which allows them to

be shared across multiple computers and applications.

fiGure 6-15

108 .

chaPter 6 SoluTionS, projecTS, And iTemS

Client application services utilize a provider model for web services extensibility. The service

providers include offline support that uses a local cache to ensure that it can still operate even when

a network connection is not available.

Client application services are discussed further in Chapter 33.

settings

Project settings can be of any type and simply reflect a name/value pair whose value can be

retrieved at run time. Settings can be scoped to either the Application or the User, as shown in

Figure 6-16. Settings are stored internally in the Settings.settings file and the app.config file. When

the application is compiled this file is renamed according to the executable being generated — for

example, SampleApplication.exe.config.

fiGure 6-16

Application-scoped settings are read-only at run time, and can only be changed by manually editing

the config file. User settings can be dynamically changed at run time, and may have a different value

saved for each user who runs the application. The default values for User settings are stored in

the app.config file, and the per-user settings are stored in a user.config file under the user’s private

data path.

Application and User settings are described in more detail in Chapter 36.

reference Paths (c# and f# only)

The Reference Paths tab, shown in Figure 6-17, is used to specify additional directories that are

searched for referenced assemblies.

Project Properties .

109

fiGure 6-17

When an assembly reference has been added, Visual Studio resolves the reference by looking in the

following directories in order:

1 The project directory.

2 Directories specified in this Reference Paths list.

3 Directories displaying files in the Add Reference dialog box.

4 The obj directory for the project. This is generally only relevant to COM interop assemblies.

signing

Figure 6-18 shows the Signing tab, which provides developers with the capability to determine how

assemblies are signed in preparation for deployment. An assembly can be signed by selecting a key

file. A new key file can be created by selecting <New…> from the file selector drop-down.

fiGure 6-18

110 .

chaPter 6 SoluTionS, projecTS, And iTemS

The ClickOnce deployment model for applications enables an application to be published to a

web site where a user can click once to download and install the application. Because this model

is supposed to support deployment over the Internet, an organization must be able to sign the

deployment package. The Signing tab provides an interface for specifying the certificate to use to

sign the ClickOnce manifests.

Chapter 46 provides more detail on assembly signing and Chapter 48 discusses ClickOnce

deployments.

My extensions (Visual basic only)

The My Extensions tab, shown in Figure 6-19, allows you to add reference to an assembly that

extends the Visual Basic My namespace, using the extension methods feature. Extension methods

were initially introduced to enable LINQ to be shipped without requiring major changes to the base

class library. They allow developers to add new methods to an existing class, without having to use

inheritance to create a subclass or recompile the original type.

fiGure 6-19

The My namespace was designed to provide simplified access to common library methods. For

example, My.Application.Log provides methods to write an entry or exception to a log file using a

single line of code. As such it is the ideal namespace to add custom classes and methods that provide

useful utility functions, global state or configuration information, or a service that can be used by

multiple applications.

Project Properties .

111

security

Applications deployed using the ClickOnce deployment model may be required to run under limited

or partial trust. For example, if a low-privilege user selects a ClickOnce application from a web site

across the Internet, the application will need to run with partial trust as defined by the Internet zone.

This typically means that the application can’t access the local filesystem, has limited networking

ability, and can’t access other local devices such as printers, databases, and computer ports.

The Security tab, illustrated in Figure 6-20, allows you to define the trust level that is required by

your application to operate correctly.

fiGure 6-20

Modifying the permission set that is required for a ClickOnce application may limit who can

download, install, and operate the application. For the widest audience, specify that an application

should run in partial trust mode with security set to the defaults for the Internet zone. Alternatively,

specifying that an application requires full trust ensures that the application has full access to all

local resources, but will necessarily limit the audience to local administrators.

Publish

The ClickOnce deployment model can be divided into two phases: initially publishing

the application and subsequent updates, and the download and installation of both the original

application and subsequent revisions. You can deploy an existing application using the ClickOnce

model using the Publish tab, shown in Figure 6-21.

112 .

chaPter 6 SoluTionS, projecTS, And iTemS

fiGure 6-21

If the install mode for a ClickOnce application is set to be available offline when it is initially

downloaded from the web site, it will be installed on the local computer. This will place the

application in the Start menu and the Add/Remove Programs list. When the application is run and a

connection to the original web site is available, the application will determine whether any updates

are available. If there are updates, users will be prompted to determine whether they want the

updates to be installed.

The ClickOnce deployment model is explained more thoroughly in Chapter 48.

code analysis (Vsts Premium and ultimate editions only)

Most developers who have ever worked in a team have had to work with an agreed-upon set

of coding standards. Organizations typically use an existing standard or create their own.

Unfortunately, standards are useful only if they can be enforced, and the only way that this can

be effectively done is using a tool. In the past this had to be done using an external utility, such as

FXCop. The VSTS Premium and Ultimate Editions of Visual Studio 2010 have the capability to

carry out static code analysis from within the IDE.

The Code Analysis tab, shown in Figure 6-22, can be used to enable code analysis as part of the

build process. Because this can be quite a time-consuming process, it may be included only in

release or test build configurations. Regardless of whether code analysis has been enabled for a

project, it can be manually invoked from the Build menu.

Web application Project Properties .

113

fiGure 6-22

Not all rules defined in the Code Analysis pane are suitable for all organizations or applications. This

pane gives the developer control over which rules are applied, and whether they generate a warning or

a build error. Deselecting the rule in the Rules column disables the rule. Double-clicking a cell in the

Status column toggles what happens when a rule fails to be met between a warning and a build error.

FXCop is covered in Chapter 13 and the native Visual Studio Code Analysis tools are discussed

further in Chapter 55.

web aPPlication ProJect ProPerties

Due to the unique requirements of web applications, four additional project property tabs are

available to ASP.NET Web Application projects. These tabs control how web applications are run

from Visual Studio as well as the packaging and deployment options.

web

The Web tab, shown in Figure 6-23, controls how Web Application projects are launched when

executed from within Visual Studio. Visual Studio ships with a built-in web server suitable for

development purposes. The Web tab enables you to configure the port and virtual path that this

runs under. You may also choose to enable NTLM authentication.

The Edit and Continue option allows editing of code-behind and standalone

class files during a debug session. Editing of the HTML in an .aspx or .ascxpage is allowed regardless of this setting; however, editing inline code in an

.aspx page or an .ascx file is never allowed.

114 .

chaPter 6 SoluTionS, projecTS, And iTemS

fiGure 6-23

The debugging options for web applications are explored in Chapter 42.

silverlight applications

The Silverlight Applications tab provides an

easy way to provide a link to a Silverlight

project and host it within an ASP.NET Web

Application.

When you add a Silverlight application to

a Web Application project, you can select

an existing Silverlight project if one exists

in the current solution, or create a new

Silverlight project as shown in Figure 6-24.

The dialog box allows you to select the

location and language for the new project,

as well as options for how the Silverlight

application will be included in the current

web application.

fiGure 6-24

Web application Project Properties .

115

If you accept the defaults when you add a new Silverlight application, Visual Studio will create a

reference to the new project and generate three files in the web application: a static HTML page, an

ASP.NET web form, and a JavaScript file that contains logic for loading Silverlight applications and

installing the run time if required.

Chapter 22 explores the development of Silverlight applications and the options for hosting them

within an existing web application.

Package/Publish web

Application deployment has always been a difficult challenge, especially when it comes to complex

web applications. A typical web application comprises not only a large number of source files and

assemblies, but also images, style sheets, and JavaScript files. To complicate matters further, it may

be dependent on a specific configuration of the IIS web server.

Visual Studio 2010 simplifies this process by allowing you to package a Web Application

project with all of the necessary files and settings contained in a single compressed (.zip) file.

Figure 6-25 shows the packaging and deployment options that are available to an ASP.NET Web

Application.

fiGure 6-25

Further discussion on web application deployment is included in Chapter 49.

116 .

chaPter 6 SoluTionS, projecTS, And iTemS

Package/Publish sql

All but the simplest of web applications are backed by a database of some description. For ASP.NET

Web applications this is typically a SQL Server database.

The Visual Studio 2010 web packaging and deployment functionality includes support for

packaging one or more SQL Server databases. As illustrated in Figure 6-26, when you create a

package you can specify a connection string for your source database and allow Visual Studio to

目录
设置
设置
阅读主题
字体风格
雅黑 宋体 楷书 卡通
字体大小
适中 偏大 超大
保存设置
恢复默认
手机
手机阅读
扫码获取链接,使用浏览器打开
书架同步,随时随地,手机阅读
首 页 < 上一章 章节列表 下一章 > 尾 页