我在Visual Studio 2008中使用调用msbuild的预构建任务:
C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe $(MSBuildProjectDirectory)\version.targets /p:Configuration=$(ConfigurationName)
Run Code Online (Sandbox Code Playgroud)
在version.targets中,我正在更新AssemblyInfo.cs文件以替换版本信息:
<FileUpdate
Encoding="ASCII"
Files="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs"
Regex="AssemblyInformationalVersion\(".*"\)\]"
ReplacementText="AssemblyInformationalVersion("Product $(ConfigurationString) ($(buildDate))")]"
/>
Run Code Online (Sandbox Code Playgroud)
当我通过Visual Studio 2008构建项目时,它构建没有任何问题.
但是当我查看生成的exe的版本信息时,它包含上一个时间戳,即使AssemblyInfo.cs已经使用"正确"更改了.
似乎主编译任务没有看到预编译的变化,它总是落后.
我做错了什么想法?
在我的java项目中,我生成的类与其他类位于同一个包文件夹中.我想配置jacoco maven插件来排除那些生成的类,只使用main/src/java文件夹中的类(不是src/main/java-generated)
项目结构:
src/main/java/com/company/john/Good.java <----这包括
src/main/java-generated/com/company/john/AutoGeneratedClass.java <----这个排除
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<includes>
</includes>
<excludes>
<exclude>**/*Dto.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我知道,1个选项是将前缀附加到生成的类,fi _并使用它进行过滤,但我想知道是否还有其他选项.如何指定源项目文件夹(src/main/java),从而排除所有其他文件夹?插件是否仅基于包名称?
我将 gRPC 框架与 Proto 3 一起使用。我们有一个 java 代码覆盖工具 Jacoco,它可以扫描 java 字节代码以查找编译类中的 java“注释”@Generate,如果有,它会从覆盖范围中跳过该 java 类。但是 Proto-compiler 添加了这个注释:
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.20.0)",
comments = "Source: myProto.proto")
public class MyClass {
...
}
Run Code Online (Sandbox Code Playgroud)
但是注释 javax.annotation.Generate 有 @Retention(value=SOURCE) ,它在编译的类中不存在。
有没有办法在编译时向 protobuf 生成的 java 文件添加注释?
我最近读了一篇关于Java注释的文章,后者是@Generated文章.他们说它用于自动生成代码.
有人可以通过一个小例子向我解释一下吗?
我在网上找到的所有内容都是一些专业问题,或者超出我想要的东西.
谢谢.
我可以在表A中创建一个生成的列,它将表B中的列与表A中的行的tableA_id相加?
假设我有一张家庭表和一张儿童表.我想要每个家庭孩子的年龄总和.
ALTER TABLE people.families
ADD COLUMN sumofages DECIMAL(10,2) GENERATED ALWAYS AS
(SELECT SUM(age) FROM people.children WHERE family_id = people.families.id) STORED;
ERROR 3102: Expression of generated column 'sumofages' contains a disallowed function.
Run Code Online (Sandbox Code Playgroud)
我无法将其保存为VIRTUAL类型.我在这做错了什么?
ALTER TABLE people.families
ADD COLUMN sumofages DECIMAL(10,2) GENERATED ALWAYS AS
(SELECT SUM(age) FROM people.children WHERE family_id = people.families.id) VIRTUAL;
ERROR 3102: Expression of generated column 'sumofages' contains a disallowed function.
Run Code Online (Sandbox Code Playgroud)
我不知道哪个功能不被禁止.SUM似乎不是它.也许SELECT?
所以我有一个像顶部一样旋转的XJC javaExec,但IntelliJ不识别生成的输出,尽管标记generated-src/java为这样.我是否需要调整插件或其他内容?
注意:插件本身从根目录加载到子项目中build.gradle.
XJC项目:
description = "Generates sources and compiles them into a Jar for $project"
configurations { xjc }
dependencies {
xjc 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
xjc 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
}
task xjc (type:JavaExec) {
doFirst{
File generatedSrcDir = file("$buildDir/generated-src/java")
if (!generatedSrcDir.exists()) {
generatedSrcDir.mkdirs()
}
}
main = "com.sun.tools.xjc.XJCFacade"
classpath configurations.xjc
def argsList = [
"-mark-generated",
"-no-header",
"-verbose", // or -quiet or nothing for default.
"-target", "2.1",
"-encoding", "UTF-8",
"-d", "$buildDir/generated-src/java",
"-catalog","$projectDir/src/main/resources/commons-gradle.cat",
file("$projectDir/src/main/resources/v1/") ]
args argsList
inputs.files files(file("$projectDir/src/main/resources/v1/"))
outputs.files files(file("$buildDir/generated-src/java"),file("$buildDir/classes")) …Run Code Online (Sandbox Code Playgroud) 我有一个用序列生成的主键定义的实体:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_key_gen")
@SequenceGenerator(name = "id_key_gen", sequenceName = "id_key_seq")
@Column(name = "id", unique = true, nullable = false)
public int getId() {
return this.id;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用PostgreSQL,这个键定义为串行.根据PostgreSQL
select last_value from id_key_seq;
Run Code Online (Sandbox Code Playgroud)
回报
1603.
Run Code Online (Sandbox Code Playgroud)
当我执行create()来持久保存此实体的实例时,我在日志中看到以下内容(编辑出的无关内容):
05 15:15:26.948 org.hibernate.id.enhanced.SequenceStructure [DEBUG] - 获得的序列值:1604
05 15:15:26.948 org.hibernate.event.def.AbstractSaveEventListener [DEBUG] - 生成的标识符:1554,使用策略:org.hibernate.id.enhanced.SequenceStyleGenerator
后续的SQL插入语句引用值1554,而不是它应该使用的值1604(基于SequenceStructure返回的值.Hibernate从哪里获得1554?
在我看来,Hibernate有一个错误 - SequenceStructure知道正确的下一个值,但它没有被使用.知道如何解决这个问题吗?
仅供参考:我知道这个页面,它说要使用GenerationType.AUTO,因为"Hibernate人员完全搞砸了",但除此之外没有太多非常有帮助的陈述.
有一个带有插件的应用程序,它以编程方式生成WCF客户端契约,然后将其连接到插件接口,但是我很难弄清楚如何让生成的契约重用插件dll中的类型.
有没有人知道如何设置ServiceContractGenerator以重用已定义程序集中的类型?
这是我用来生成合同代码atm:
public Assembly CreateProxy(String url)
{
MetadataExchangeClient mexClient = new MetadataExchangeClient(new Uri(url + "/mex"), MetadataExchangeClientMode.MetadataExchange);
mexClient.ResolveMetadataReferences = true;
MetadataSet metaDocs = mexClient.GetMetadata();
WsdlImporter importer = new WsdlImporter(metaDocs);
ServiceContractGenerator generator = new ServiceContractGenerator();
generator.NamespaceMappings.Add("*", "NameSpace123");
Collection<ContractDescription> contracts = importer.ImportAllContracts();
ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();
foreach (ContractDescription contract in contracts)
generator.GenerateServiceContractType(contract);
if (generator.Errors.Count != 0)
throw new Exception("There were errors during code compilation.");
CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("C#");
CompilerParameters parameters = new CompilerParameters();
parameters.CompilerOptions = string.Format(@" /lib:{0}", "\"C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.0\"");
parameters.ReferencedAssemblies.Add("System.ServiceModel.dll");
parameters.ReferencedAssemblies.Add("System.Runtime.Serialization.dll"); …Run Code Online (Sandbox Code Playgroud) 假设我想以随机顺序生成 1-1000 之间的所有整数。但...
我认为这应该是不可能的,但也许我只是没有考虑正确的解决方案。
我想在 C# 中使用它,但我对方法比实际实现更感兴趣。
有没有办法从.net代码以编程方式启用Adobe PDF使用权限?我正在使用ITextSharp库来填充带有XML数据的XFA表单(从应用程序生成),但输出PDF没有启用使用权限,因此用户无法与之交互(这通常不会成为问题,但是原始PDF是gov提供的,用户必须单击一些验证按钮,该过程是用户/公司特定的)
这可以通过Adobe Reader手动完成,但您必须拥有adobe acrobat专业许可证.
谷歌说"只有Adobe产品可以做到这一点"..(http://old.nabble.com/Enable-Adobe-Reader-usage-rights-td14276927.html)
string pathPDF = @"C:\original.pdf";
string pathCreated = @"C:\created.pdf";
string pathXml = @"C:\data.xml";
using (PdfStamper stamper = new PdfStamper(new PdfReader(pathPDF), System.IO.File.OpenWrite(pathCreated)))
{
stamper.FormFlattening = false;
stamper.AcroFields.Xfa.FillXfaForm(pathXml);
stamper.Close();
}
Run Code Online (Sandbox Code Playgroud)