compilation 的 compilers 元素

<compilers>
        <compiler language="c#" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
          compilerOptions="/d:DEBUG;TRACE /unsafe+" />
      </compilers>

compilation 的 compilers 元素(ASP.NET 设置架构)指定 ASP.NET 应用程序支持的编译器。

<compilers> 元素包含零个或多个 <compiler> 元素。每个 <compiler> 元素为一个特定语言提供程序指定编译器配置属性。

在 .NET Framework 2.0 版中,此元素已被否决,而改为使用 system.codeDom 节的 compilers 元素。但是,使用 compilation 元素的 compilers 子元素仍然有效,并且将重写位于 system.codedom 节中的 compilers 元素。

在本系统中由于图片的水印效果处理功能中使用了指针,请在web.config中加入下面项:
<system.web> 
  <compilation defaultLanguage="c#" debug="true">
<compilers>
<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs" compilerOptions="/unsafe" />
</compilers>
</compilation>
</system.web>

如何在c#中使用指针
1、修改工程配置

工程中默认的配置是不支持代码的非安全性的,如果我们想使用指针就要修改这个默认的设置。否则我们在编译的时候就会出现“不安全代码只会在使用/unsafe编译的情况下出现”。

<system.web> 
  <compilation defaultLanguage="c#" debug="true">
<compilers>
<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs" compilerOptions="/unsafe" />
</compilers>
</compilation>
</system.web>

2、定义非安全代码
在C#中如果想使用指针就需要将代码定义为unsafe。unsafe是C#中的一个关键字,我们可以将一个类、一个方法、代码块或者字段标记为unsafe。剩下的工作就和在其它语言中使用指针相同了。下面是一个使用指针的代码演示。

None.gif        //将方法声明为非安全
None.gif
        public unsafe void Test()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
int i=10;
InBlock.gif            
int k;
InBlock.gif            
//定义指针
InBlock.gif
            int *j;
InBlock.gif            
//给指针赋值
InBlock.gif
             j=&i;
InBlock.gif            
//取的指针的值            
InBlock.gif
             k=*j+1;
InBlock.gif             MessageBox.Show(k.ToString());
ExpandedBlockEnd.gif         }

D:\004 newCoinInfo>java -version java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode) D:\004 newCoinInfo>echo %JAVA_HOME% D:\JDK 但是 D:\004 newCoinInfo>mvn clean package [INFO] Scanning for projects... [INFO] [INFO] ------------------------< com.example:test_reg >------------------------ [INFO] Building test_reg 0.0.1-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- clean:3.2.0:clean (default-clean) @ test_reg --- [INFO] Deleting D:\004 newCoinInfo\target [INFO] [INFO] --- resources:3.2.0:resources (default-resources) @ test_reg --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] Copying 1 resource [INFO] Copying 1 resource [INFO] [INFO] --- compiler:3.10.1:compile (default-compile) @ test_reg --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 7 source files to D:\004 newCoinInfo\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.914 s [INFO] Finished at: 2023-07-19T18:31:17+08:00 [INFO] ------------------------------------------------------------------------ [WARNING] [WARNING] Plugin validation issues were detected in 2 plugin(s) [WARNING] [WARNING] * org.apache.maven.plugins:maven-resources-plugin:3.2.0 [WARNING] * org.apache.maven.plugins:maven-compiler-plugin:3.10.1 [WARNING] [WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE] [WARNING] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project test_reg: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 报错
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值